Start Cell "A2"

josros60

Well-known Member
Joined
Jun 27, 2010
Messages
780
Office Version
  1. 365
Hi,
have the code below but when executed the values are put at the bottom starting at cell "A71" how can make to start at the top starting on cell "A2".


here is the code:

VBA Code:
Sub FIND_DIFFERENCES()
  Dim sh1 As Worksheet, sh2 As Worksheet, sh3 As Worksheet
  Dim C As Range, f As Range, mydiffs As Long
  Dim r1 As Range, r2 As Range, lr As Long
  
  Set sh1 = Sheets("NCL_INVOICES")
  Set sh2 = Sheets("VENDOR_INVOICES")
  Set sh3 = Sheets("DIFFERENCES")
  
  Set r1 = sh1.Range("A2", sh1.Range("A" & Rows.Count).End(xlUp))
  Set r2 = sh2.Range("A2", sh2.Range("A" & Rows.Count).End(xlUp))
 
  r1.Interior.Color = vbWhite
  r2.Interior.Color = vbWhite
  
  For Each C In r1
    Set f = r2.Find(C, , xlValues, xlWhole)
    If f Is Nothing Then
      C.Interior.Color = vbRed
      mydiffs = mydiffs + 1
      lr = sh3.Range("A" & Rows.Count).End(xlUp).Row + 1
      sh3.Range("A" & lr).Resize(1, 6).Value = C.Resize(1, 6).Value
      sh3.Range("A" & lr).Offset(, 6).Value = sh1.Name
     
      
      
      
    End If
  Next
  For Each C In r2
    Set f = r1.Find(C, , xlValues, xlWhole)
    If f Is Nothing Then
      C.Interior.Color = vbRed
      mydiffs = mydiffs + 1
      lr = sh3.Range("A" & Rows.Count).End(xlUp).Row + 1
      sh3.Range("A" & lr).Resize(1, 6).Value = C.Resize(1, 6).Value
      sh3.Range("A" & lr).Offset(, 6).Value = sh2.Name
      
    End If
  Next
  MsgBox mydiffs & " differences found"
End Sub

thank you
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Should it always start in A2 even if there is data already there?
 
Upvote 0
There's no data there, always clear cause is template.

should Always start A2.

thank you
 
Upvote 0
If that was the case then your code would start putting values in A2 & not A71.
I would check that those cells are indeed empty.
 
Upvote 0
here a sample top empty and start at 21:

VENDOR_RECONCILIATION_TEMPALTE.xltm
ABCDEFGH
1INVOICE #DATEENTRYNCL_AMTREFERENCEVEND_AMTTABSPAID
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
215672111/9/20211362-16$467.51NCL_INVOICES
22575651/13/20221467-7$249.38NCL_INVOICES
23577912/1/20221498-7$374.06NCL_INVOICES
24578124/6/20221604-2$149.63MOVED FROM SAGEID 1003NCL_INVOICES
25581933/1/2022$4,310.89VENDOR_INVOICES
26581943/1/2022$2,324.07VENDOR_INVOICES
27585943/1/2022$157.50VENDOR_INVOICES
28587824/7/2022$462.26VENDOR_INVOICES
29588564/13/2022$289.26VENDOR_INVOICES
30588574/13/2022$778.84VENDOR_INVOICES
DIFFERENCES


thank you
 
Upvote 0
Is that a structured table or just a normal range?
 
Upvote 0
So you have a table with loads of totally blank rows? Why, it defeats the whole point of a table.
 
Upvote 0
Solution
Yes, that's was the problem converted back to range and it worked.

thank you so much for the input.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,013
Messages
6,122,690
Members
449,092
Latest member
snoom82

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