VBA Activate Cell

chaddres

Board Regular
Joined
Jun 14, 2014
Messages
143
Office Version
  1. 365
Platform
  1. Windows
After I run this macro how do I activate lastcol2? That is, row 2 of the last column. I tried "Range(Cells(lastcol + 1), 2).Activate" but that did not work.

VBA Code:
'Multiple Rate Check
    Sheets("Combined Time").Select
    Dim rng2 As Range
    Dim sht2 As Worksheet
    Dim pTable2 As PivotTable
    Set rng2 = ActiveSheet.Cells(1, 1).CurrentRegion
    Set sht2 = ActiveWorkbook.Worksheets.Add
    sht2.Name = "Rate Check Pivot"
    Set pTable2 = ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        rng2.Address, Version:=8).CreatePivotTable(TableDestination:= _
        sht2.Cells(1, 1), TableName:="PivotTable" & Format(Time, "hhmmss"))
    With pTable2
        With .PivotFields("SSN")
            .Orientation = xlRowField
            .Subtotals(1) = False
        End With
        With .PivotFields("Temp Rate")
            .Orientation = xlColumnField
            .Subtotals(1) = False
        End With
        .PivotFields("Reg Hours").Orientation = xlDataField
    End With
    Range("B3").Select
    Dim lastcol As Long
    lastcol = Cells(ActiveCell.Row, Columns.Count).End(xlToLeft).Column
    Cells(ActiveCell.Row, lastcol + 1).Select
    ActiveCell.Value = "=COUNT(RC[" & (1 - lastcol) & "]:RC[-2])"
    With ActiveCell
        Range(Cells(3, lastcol + 1), Cells(Range("A" & Rows.Count).End(xlUp).Row - 1, lastcol + 1)).FillDown
    End With
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Try:
VBA Code:
Cells(2, lastCol).Activate
Note the format of Cells is Cells(row, column)
 
Upvote 0
Solution

Forum statistics

Threads
1,214,641
Messages
6,120,695
Members
448,979
Latest member
DET4492

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