Message box that shows the column and the last data in that column.

danbates

Active Member
Joined
Oct 8, 2017
Messages
377
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I've tried looking this up but I haven't found anything close to what I am wanting.

I would like a code that when triggered, shows the column letter and what data is in the last row of that column in a message box.

The columns are A to L.

I hope this makes sense and any help would be much appreciated.

Thanks

Dan
 
I was wondering if it was possible to do the following:

1. Double tab columns A, B, C & F and single tab the rest? It would line everything up perfectly.
Try ..
Rich (BB code):
Sub LastValuesAllColumns_v3()
  Dim i As Long
  Dim msg As String
  Dim cLast As Range
  Dim aTabs As Variant
  
  aTabs = Split("2 2 2 1 1 2 1 1 1 1 1 1")
  For i = 1 To 12
    Set cLast = Columns(i).Find(What:="*", LookIn:=xlValues, SearchDirection:=xlPrevious)
    msg = msg & vbLf & Cells(2, i).Value & " :"
    If cLast.Row > 2 Then msg = msg & String(aTabs(i - 1), vbTab) & cLast.Text
  Next i
  MsgBox msg
End Sub


2. Have column C & F in red?
No, but you could highlight them by adding the blue lines of code below.
You might need to experiment with the red numbers to suit your headings & data.

Rich (BB code):
Sub LastValuesAllColumns_v4()
  Dim i As Long
  Dim msg As String
  Dim cLast As Range
  Dim aTabs As Variant
  
  aTabs = Split("2 2 2 1 1 2 1 1 1 1 1 1")
  For i = 1 To 12
    Set cLast = Columns(i).Find(What:="*", LookIn:=xlValues, SearchDirection:=xlPrevious)
    If i = 3 Or i = 6 Then msg = msg & vbLf & String(40, "-")
    msg = msg & vbLf & Cells(2, i).Value & " :"
    If cLast.Row > 2 Then msg = msg & String(aTabs(i - 1), vbTab) & cLast.Text
    If i = 3 Or i = 6 Then msg = msg & vbLf & String(40, "-")
  Next i
  MsgBox msg
End Sub
 
Last edited:
Upvote 0

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hi Peter_SSs,

I just wanted to thank you for all your help, my message box is perfect now.

Regards

Dan
 
Upvote 0
Hi Peter_SSs,

I just wanted to thank you for all your help, my message box is perfect now.

Regards

Dan
Cheers. Glad we got something suitable in the end. Thanks for the follow-up. :)
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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