Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA newbie needs help

Status
Not open for further replies.

SLW89

MIS
Mar 28, 2024
2
0
0
GB
Hi, im fairly new to VBA and need help breaking down this code my predecessor created:
Sub fCopyAHTs()
'Copies the AHTs created to the Daily Tab for reference
Dim lngRow As Long, lngPasteRow As Long
Dim lngCol As Long, lngPasteCol As Long
Dim lngLoop As Long, lngColLoop As Long
Dim lngRowCol As Long, lngDays As Long
Dim strSearch(1) As String
Dim dblResult As Double

'hold variables
lngRow = fFindItem("Days in Month", True, "Build")
lngRowCol = fFindItem("Days in Month", False, "Build") - 1
lngDays = Build.Cells(lngRow, lngRowCol) - 1

lngRow = fFindItem("WeekDay", True, "Output") + 1
lngRowCol = fFindItem("WeekDay", False, "Output") - 1

strSearch(0) = "Working AHT"
strSearch(1) = "Budget AHT"

'loop through the two columns to be copied
For lngColLoop = 0 To 1

lngCol = fFindItem(strSearch(lngColLoop), False, "Output")
lngPasteCol = fFindItem(strSearch(lngColLoop), False, "Daily")

'loop through each day of the month
For lngLoop = 0 To lngDays

dblResult = Output.Cells(lngRow + lngLoop, lngCol)

lngPasteRow = Output.Cells(lngRow + lngLoop, lngRowCol)

Daily.Cells(lngPasteRow, lngPasteCol) = dblResult

Next

Next

End Sub

i cant figure out what fFindItem means and strSearch(0) but the rest i can just about manage to figure out what its doing. any help would be greatly appreciated
 
Hi,

A hint to me would be...
Sub fCopyAHTs()

...the structure of the name of your procedure.

Any other procedures in your VBA Project?

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein

You Matter...
unless you multiply yourself by the speed of light squared, then...
You Energy!
 
be cause it has an f at the start of CopyAHTs?
there are afew in the workbook but the one before is this:
Sub sCopyout()
'Filters out unnecessary intervals and copies data for input in to the DB
Dim lngRow As Long

Application.ScreenUpdating = False

Output.Range("$A$1:$L$100000").AutoFilter Field:=12, Criteria1:="TRUE"
lngRow = Output.Range("A100000").End(xlUp).Row

DB_Input.Select
DB_Input.Range(Cells(2, 1), Cells(100000, 11)).ClearContents

Output.Range("A2:K" & lngRow).Copy

DB_Input.Cells(2, 1).Select
ActiveSheet.Paste

Application.CutCopyMode = False
Application.ScreenUpdating = True

Output.Range("$A$1:$L$100000").AutoFilter Field:=12

Call fCopyAHTs

End Sub
 
First try to find the root procedure called, it may be 'sCopyout' that calls 'fCopyAHTs', but there may be something else. Depending on the design, there may be an activex button with event procedure in parent form/worksheet, forms button with assigned procedure or just running the code in VBE or from the list of macros.

SLW89 said:
i cant figure out what fFindItem means
There should be a function definition somewhere in the code. Unless the VBA application uses other projects, as add-in or 'Personal' workbook or other workbook linked. Anyway, The current project is the first place to check.

SLW89 said:
... and strSearch(0)
'1' in [tt]Dim strSearch(1) As String[/tt] and [tt]strSearch(1) = "Budget AHT"[/tt] has different meanings.
The 'strSearch' array is declared, with [tt]Dim strSearch(1) As String[/tt], as as text array, 1D - 'strSearch' in declaration has one argument, and 1 as the largest subscript in first dimension - the value of first argument in declaration. So it can accept two entries (guess that default base 0 was not changed).
Later on, there is an assignment of array first item [tt]strSearch(0) = "Working AHT"[/tt] and second item [tt]strSearch(1) = "Budget AHT"[/tt].


combo
 
SLW89 said:
i cant figure out what fFindItem means

It is a Function in your code where you pass a String, a Boolean, and another String, for example: ("Days in Month", True, "Build"). To find this code, put your cursor anywhere in fFindItem (or select entire word fFindItem) and hit Shift-F2.
Or: Right_Click on the word fFindItem and select Definition

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top