Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

VBA newbie needs help

VBA newbie needs help

VBA newbie needs help

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



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

RE: VBA newbie needs help


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

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

Any other procedures in your VBA Project?


glassesJust traded in my OLD subtlety...
for a NUance!tongue

"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!

RE: VBA newbie needs help

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.Range(Cells(2, 1), Cells(100000, 11)).ClearContents

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

DB_Input.Cells(2, 1).Select

Application.CutCopyMode = False
Application.ScreenUpdating = True

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

Call fCopyAHTs

End Sub

RE: VBA newbie needs help

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.

Quote (SLW89)

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.

Quote (SLW89)

... and strSearch(0)
'1' in Dim strSearch(1) As String and strSearch(1) = "Budget AHT" has different meanings.
The 'strSearch' array is declared, with Dim strSearch(1) As String, 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 strSearch(0) = "Working AHT" and second item strSearch(1) = "Budget AHT".


RE: VBA newbie needs help

Quote (SLW89)

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close