theberner,
Exactly what is not working? Ut does not look like your code would execute flawlessly, but we need to findout wehre and why.
First, I would make a couple recommendations, then a few observations.
First, beginning of your code should look like this:
- Option Compare Text
-
Option Explicit
-
-
Sub Checker2()
-
Dim fRowNum As Integer
-
Dim fColumNum As Integer
-
Dim fTRow As Integer
-
Dim fWorkbookName As String
-
Dim fName As String
-
Dim fPathName As String
-
Dim fFileName As String
The statement "Option Explicit" ensure that all variables used must be declared. This is a standard VBA coding practice, which can be set by default, and I encourage you to use it always. This is followed by declaring all your variables and declaring the type of variable it is. Again, standard VBA practices.
One particular reason this would be helpful in your case is that you set values for the variables fRowNum, fColumNum and fTRow (all set to 2), yet it appears the only time you refer again to fRowNum is lines 60-62. But, then you efer to fRow and fRowB and it is unclear when, where and why these variables exist.
However, trying to interpret your code, it appears you are working with two different workbooks, trying to copy and paste between the two?
This can be very tricky as sometimes MS Excel has problems disambiguating between the active workbook.
In this case, it is sometimes better to declare a variable of the workbook or worksheet, so that whenever you refer to that variable, the VBA knows exactly which workbook/worksheet you mean. Here is an example:
- Dim xlApp As Excel.Application
-
Dim wbOriginal As Excel.Workbook
-
Dim wbNew As Excel.Workbook
-
Dim wsOriginal As Excel.Worksheet
-
Dim wsNew As Excel.Worksheet
-
-
Set xlApp = New Excel.Application
-
xlApp.Visible = False
-
Set wbOriginal = xlApp.Workbooks.Open("Path\Filename.xlsx")
-
Set wbNew = xlApp.Workbooks.Open("Path\Filename2.xlsx")
-
Set wsOriginal = wbOriginal.Sheets(1)
-
Set wsNew = wbNew.Sheets(1)
-
With wsNew
-
.Cells(1, 1) = "Test"
-
End With
Now, whenever you want to refer to one Worksheet/Workbook or the other, you just use the variable for that particular workbook. There is much flexibility in this method.
If there are particular errors you are receiving, I would be glad to try and work thorugh those with you.
Hope this helps.