trying to select two columns

Mr Rice

New Member
Joined
Nov 30, 2022
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hi,

Please bare with me as i am just now getting into learning Excel and VBA for my employer.

i am working on a project and i need a vba code to select two columns based off last row of column A and then select blanks within these two columns. Column A will never have blanks since it's set as dynamic within my Master file so finding last row is easy and will never have a blank while using the userform. i want to find all blanks within Column A. I have an inputbox to enter the desired initials i want within the blanks the vba code finds. below is what i used but it selects the full columns. i have been testing several codes but this was the closest i got.

VBA Code:
Private Sub FakeName_Click()
 Dim ar
    Dim cell As Range
    Dim inputvalue As String
    Dim msgvalue as VbMsgBoxResult
     inputvalue = InputBox("Please make sure blanks are selected", _
    "Fill Empty Cells")
    
    Range("A:B").Select
    Selection.SpecialCells(xlCellTypeBlanks).Select

msgvalue = msgbox ("Please verify the selected area", vbokcancel + vbinformation, "Ready?")

If vbCancel Then Exit Sub
If vbokay Then
    
    For Each cell In Selection

        If IsEmpty(cell) Then
        cell.Value = inputvalue
            Else: Exit Sub
     End If
    Next
    
End Sub

Test.xlsm
ABCDE
1# of entriesInitialsEXPLANATIONSSales OrderShip Date
21JC107138011/23/2022
32JCCANCELLED107143711/28/2022
43SHIPPED107122311/29/2022
54JCSHIPPED107202811/29/2022
65JCSHIPPED107202811/29/2022
76JCSHIPPED107221611/29/2022
87JCSHIPPED107222611/29/2022
98JCSHIPPED107221011/29/2022
109KW106779811/30/2022
1110JC107143911/30/2022
1211JC107143911/30/2022
1312JC107143911/30/2022
1413JCLABEL ROOM107143911/30/2022
1514JC107143911/30/2022
1615SHIPPED107188511/30/2022
1716SHIPPED107223111/30/2022
1817JCSHIPPED107236611/30/2022
1918JCSHIPPED107235611/30/2022
2019JCLABEL ROOM107236311/30/2022
2120AlexSHIPPED107243311/30/2022
2221AlexSHIPPED107242611/30/2022
2322AlexJUST ENTERED107242511/30/2022
2423JCSHIPPED107179412/1/2022
2524JCSHIPPED107179412/1/2022
2625JCSHIPPED107162412/1/2022
2726JCSHIPPED107211712/1/2022
2827JC107210812/1/2022
2928JCLABEL ROOM107203112/1/2022
3029JCLABEL ROOM107203112/1/2022
3130JCSHIPPED107203212/1/2022
3231JCSHIPPED107203212/1/2022
3332JCSHIPPED107203912/1/2022
3433JCSHIPPED107203912/1/2022
3534JCLABEL ROOM107204912/1/2022
3635JCLABEL ROOM107204912/1/2022
3736JCLABEL ROOM107204912/1/2022
3837JCSHIPPED107221712/1/2022
3938JCLABEL ROOM107220512/1/2022
4039JCLABEL ROOM107216812/1/2022
4140JCLABEL ROOM107216812/1/2022
Sheet1
Cell Formulas
RangeFormula
A2:A41A2=ROW()-1
Cells with Conditional Formatting
CellConditionCell FormatStop If True
D2:D1048576Expression=$C2="JUST ENTERED"textNO
E2:E1048576Expression=$C2="JUST ENTERED"textNO
C2:C1048576Cell Valuecontains "JUST ENTERED"textNO
C2:C1048576Expression=$C2="JUST ENTERED"textNO
C2:C1048576Cell Valuecontains "LABEL ROOM"textNO
C2:C1048576Cell Valuecontains "Problem"textNO
C2:C1048576Cell Valuecontains "NOT PULLED"textNO
C2:C1048576Cell Valuecontains "PARTIAL SHIP"textNO
C2:C1048576Cell Valuecontains "Small Parts"textNO
C2:C1048576Cell Valuecontains "CANCELLED"textNO
C2:C1048576Cell Valuecontains "PAINTING"textNO
C2:C1048576Cell Valuecontains "SHIPPED"textNO
C2:C1048576Cell Valuecontains "PULLED/ NOT DONE"textNO
C2:C1048576Cell Valuecontains "BACKORDER"textNO
1669835567647.png
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Welcome to the Forum.

See if this does what you need.

Note: Conditional formatting is a Volatile Function and will slow down your spreadsheet. You have applied it to over 1M rows.
Also by not checking the box "Stop If True" even if the first condition is true it is still going to evaluate all the others so your column C is going to run through all 1M rows 12 times even if the first condition is met.

VBA Code:
Private Sub FakeName_Click()
 Dim ar
    Dim cell As Range
    Dim inputvalue As String
    Dim msgvalue As VbMsgBoxResult
    Dim lRow As Long
    Dim rngBlnk As Range
   
     inputvalue = InputBox("Please make sure blanks are selected", _
    "Fill Empty Cells")
   
    lRow = Range("A" & Rows.Count).End(xlUp).Row
    Set rngBlnk = Range("B2:B" & lRow).SpecialCells(xlCellTypeBlanks)
    rngBlnk.Select

msgvalue = MsgBox("Please verify the selected area", vbOKCancel + vbInformation, "Ready?")

If msgvalue = vbCancel Then Exit Sub
If msgvalue = vbOK Then
   
    For Each cell In rngBlnk
        If IsEmpty(cell) Then
            cell.Value = inputvalue
        Else: Exit Sub
        End If
    Next
End If
   
End Sub
 
Last edited:
Upvote 0
Solution
Looks like your code did the trick! Thank you very much. 😁
 
Upvote 0

Forum statistics

Threads
1,215,338
Messages
6,124,360
Members
449,155
Latest member
ravioli44

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