set range

atbenline

New Member
Joined
Feb 18, 2018
Messages
8
Hi, I have hit a wall trying to create a macro to set a range using the last column with data and column "C". Column "C" being the constant and the other column always changing.

macrohelp.JPG


Thanks for any help,

Tyler
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
I am currently changing the "X" value manually before I run the macro. I would like to have the macro select the last column without having to modify the macro.

Range("X:X,C:C").Select
 
Upvote 0
Maybe
VBA Code:
Sub atbenline()
   Dim UsdCols As Long, UsdRws As Long
   Dim MyRange As Range
   
   UsdCols = Cells.Find("*", , xlValues, , xlByColumns, xlPrevious, , , False).Column
   UsdRws = Range("C" & Rows.Count).End(xlUp).row
   Set MyRange = Union(Range("C1:C" & UsdRws), Cells(1, UsdCols).Resize(UsdRws))
End Sub
 
Upvote 0
It is not selecting the columns to generate a range? It is not selecting the columns necessary to complete conditional formatting I am trying to achieve. It is skipping to hiding of the last column "X:X". I probably should have been more specific in what it is I am trying to get done.

VBA Code:
 Dim UsdCols As Long, UsdRws As Long
    Dim MyRange As Range
    UsdCols = Cells.Find("*", , xlValues, , xlByColumns, xlPrevious, , , False).Column
    UsdRws = Range("C" & Rows.Count).End(xlUp).Row
    Set MyRange = Union(Range("C1:C" & UsdRws), Cells(1, UsdCols).Resize(UsdRws))
    Range("C1").Activate
    Selection.FormatConditions.AddUniqueValues
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    Selection.FormatConditions(1).DupeUnique = xlDuplicate
    With Selection.FormatConditions(1).Font
        .Bold = True
        .Italic = False
        .Color = -16776961
        .TintAndShade = 0
    End With
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 13158625
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
    Columns("X:X").Select
    Selection.EntireColumn.Hidden = True

Thanks
 
Upvote 0
What exactly are your trying to do?
 
Upvote 0
Select column "C" and the last column. Highlight duplicate vales in those two columns. Then hide the last column.
 
Upvote 0
In that case everywhere you have "Selection" replace it with MyRange
 
Upvote 0

Forum statistics

Threads
1,223,785
Messages
6,174,537
Members
452,571
Latest member
MarExcelTips

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