jdhfch

Board Regular
Joined
Jan 25, 2018
Messages
69
Office Version
  1. 365
Platform
  1. Windows
HI,

I am trying to adapt an existingVBA project to copy 11 worksheets from a folder into one workbook, then update a master template.

In Column A I have “ABM”, then it runs along for 32 more columns, row 1 is the titles which I don’t need to copyover. There is only 1 worksheet per workbook and each sheet is called the same then renamed after being copied over.

I am using this code, but itkeeps failing at IntABMRow = 2 with a “Compile error: Variable not defined”error (please bear in mind this is copied from a different workbook so it may be source related ?


Private SubUpdate_Master_Template()

Dim sh As Worksheet
Dim strMasterFile As String
Dim strMasterSheet As String
Dim strMaster2019 As String
Dim intMasterRow As Integer
Dim intMaster2019Row As Integer
Dim strCurrentABMSheet As String
Dim intABMRowTotal As Integer
Dim Counter As Integer
Dim Counter2 As Integer
Dim Counter3 As Integer
Dim intMasterRowTotal As Integer

strMasterFile = ActiveWorkbook.Name
strMaster2019 = Sheet1.Name


intMaster2019Row = 2


Application.DisplayAlerts = False
For Each sh In Worksheets

If sh.Name <>strMaster2019 Then

intABMRow = 2

strCurrentABMSheet = sh.Name

If Left(strCurrentABMSheet, 1)= "Non" Then
strMasterSheet =strMaster2019
intMasterRow = intMaster2019Row
ElseIfLeft(strCurrentABMSheet, 1) = "2019" Then
strMasterSheet = str2019
intMasterRow =intMaster2019Row
Else
GoTo NextSheet:

End If


intABMRowTotal =Sheets(strCurrentABMSheet).Range("A3").CurrentRegion.Rows.Count - 1

For Counter = 1 TointABMRowTotal

IfSheets(strCurrentABMSheet).Cells(intABMRow, 5) <> "" Then
For Counter2 = 1 To10
Sheets(strMasterSheet).Cells(intMasterRow, Counter2 + 2) =Sheets(strCurrentABMSheet).Cells(intABMRow, Counter2 + 2)
Next Counter2
intABMRow =intABMRow + 1

intMasterRow =intMasterRow + 1

If strMasterSheet = str2019 Then
intMaster2019Row = intMasterRow

End If

End If
Next Counter

End If

NextSheet:

Next sh
Application.DisplayAlerts = True

Please can someone help, I am a complete novice to VBA!
 
Last edited:

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Hi,
what that error means is that at Top of your module you have Option Explicit declared which is good as it requires that you declare all variables used in your code.

Quick glance at your code suggests that following two variables are not declared

Code:
Dim intABMRow As Long, str2019 As String

Try adding these in your declarations section of your code & see if problem resolves itself.

Dave
 
Upvote 0
Thank you. Unfortunatly it still errors

Just pasted in to code sheet & compiled ok - where does it error & what is the error code?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,632
Messages
6,120,649
Members
448,975
Latest member
sweeberry

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top