trying to find the last cell of row 2

288enzo

Well-known Member
Joined
Feb 8, 2009
Messages
721
Office Version
  1. 2016
Platform
  1. Windows
I need to add data to the last column, in this case it would be "H". The macro will be ran on different workbooks where the number of columns can change.

I thought the following would work.

VBA Code:
    Lcol As Long
    Lcol = Cells(2, Columns.Count).End(xlToLeft).Column
    Dim rng As Range
    rng = Range("A2")
    rng.Offset(0, Lcol).Select

Copy of Area 84 IND Sept-October.xlsm
BCDEFGH
2600336A3600336PL600336SSIFU600336SSIVD600336VIQS601036F
3857306
4110100
5220100
6420000
7120101
8130000
9100111
10043112
11020000
12006001
13001021
14000101
15000200
report
Cell Formulas
RangeFormula
B3:G15B3=COUNTIFS(data!$H:$H,$A3,data!$A:$A,B$2)
Named Ranges
NameRefers ToCells
data!_FilterDatabase=data!$A$3:$AI$3B3:G15


Trying to do this

Copy of Area 84 IND Sept-October.xlsm
BCDEFGH
1
2600336A3600336PL600336SSIFU600336SSIVD600336VIQS601036FTotal
385730629
41101003
52201005
64200006
71201015
81300004
91001114
1004311211
110200002
120060017
130010214
140001012
150002002
report
Cell Formulas
RangeFormula
B3:G15B3=COUNTIFS(data!$H:$H,$A3,data!$A:$A,B$2)
H3:H15H3=SUM(B3:G3)
Named Ranges
NameRefers ToCells
data!_FilterDatabase=data!$A$3:$AI$3B3:G15


Thank you as usual, this forum has been amazing.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
How about
VBA Code:
    Dim Lcol As Long
    Lcol = Cells(2, Columns.Count).End(xlToLeft).Column
    Dim Rng As Range
    Set Rng = Range("A2")
    Rng.Offset(0, Lcol).Select
 
Upvote 0
Solution
How about
VBA Code:
    Dim Lcol As Long
    Lcol = Cells(2, Columns.Count).End(xlToLeft).Column
    Dim Rng As Range
    Set Rng = Range("A2")
    Rng.Offset(0, Lcol).Select
Darn it, I was so close. Only missing Set. Thanks Fluff.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,414
Messages
6,119,375
Members
448,888
Latest member
Arle8907

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