Extract all words from one table written with all caps and put in other excel sheet

Vallenato

New Member
Joined
Oct 18, 2017
Messages
13
Hello!
I have a sheet containing rows with data. In the B column of each row there is a word written, sometimes with small caps, sometimes with all caps and sometimes with both. I would like excel to automatically (without button) show the B and D column of rows containing only all caps words in the B column (if there are numbers combined with the all caps that's OK too) in another worksheet (in column A and C in sheet2, showing the B column names from Sheet1 starting with a cap and then the rest of the word with small caps) and keep it always updated in case I make changes in sheet 1. Is there a way to do this with vba?

An example of sheet1:

car Rob 44 87
bike Jon1 37 98
plane MIKE 87 79
dog Ron 77 98
cat JAY1 65 12


and sheet2 will show:

Mike 79
Jay1 12
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Give this macro a try...
Code:
[table="width: 500"]
[tr]
	[td]Sub ExtractAllCaps()
  Dim R As Long, X As Long, Data As Variant, Result As Variant
  Data = Sheets("Sheet1").Range("B1", Sheets("Sheet1").Cells(Rows.Count, "D").End(xlUp))
  ReDim Result(1 To UBound(Data), 1 To 2)
  For R = 1 To UBound(Data)
    If Not Data(R, 1) Like "*[!A-Z0-9]*" Then
      X = X + 1
      Result(X, 1) = Data(R, 1)
      Result(X, 2) = Data(R, 3)
    End If
  Next
  Sheets("Sheet2").Range("A1").Resize(UBound(Result), 2) = Result
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
Hello Rick!
It works! Thank you!!! Two questions:

1. Is it possible to make the code work as well if there is a blank row in between rows with data and sheet 2 doesn´t get this blank row (i.e. JAY1 in the example below gets copied directly under MIKE without the blank row in sheet2)?

For example if sheet1 would look like this:

car Rob 44 87
bike Jon1 37 98
plane MIKE 87 79
dog Ron 77 98

cat JAY1 65 12


Sheet2 will still show:

Mike 79
Jay1 12

2. And finally, to get the all caps in column A in sheet2 to change so that it says Mike and not MIKE in this target sheet?
 
Last edited:
Upvote 0
This should do it for you...
Code:
[table="width: 500"]
[tr]
	[td]Sub ExtractAllCaps()
  Dim R As Long, X As Long, Data As Variant, Result As Variant
  Data = Sheets("Sheet1").Range("B1", Sheets("Sheet1").Cells(Rows.Count, "D").End(xlUp))
  ReDim Result(1 To UBound(Data), 1 To 2)
  For R = 1 To UBound(Data)
    If Not Data(R, 1) Like "*[!A-Z0-9]*" And Len(Data(R, 1)) > 0 Then
      X = X + 1
      Result(X, 1) = Application.Proper(Data(R, 1))
      Result(X, 2) = Data(R, 3)
    End If
  Next
  Sheets("Sheet2").Range("A1").Resize(UBound(Result), 2) = Result
End Sub[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0
Hello Rick!
Thanks again for your kindness taking time to help me with this vba-issue. Now the macro works quite fine! But after testing it I found two things that isn´t really working as I thought it would.

First, if I don´t write anything in column D it will not copy column B to Sheet2. There may be rows were column D will have a blank value in Sheet1 and then I still want column B to be copied from Sheet1 to Sheet2.

Second, if I delete rows in Sheet1 it will not delete the corresponding rows in Sheet2 (it only seems to be working with the first row?!).

Could you add something to the code to get these two details to work better? Thank you again for your effort!!!
 
Last edited:
Upvote 0
Hello Rick!
Thanks again for your kindness taking time to help me with this vba-issue. Now the macro works quite fine! But after testing it I found two things that isn´t really working as I thought it would.

First, if I don´t write anything in column D it will not copy column B to Sheet2. There may be rows were column D will have a blank value in Sheet1 and then I still want column B to be copied from Sheet1 to Sheet2.

Second, if I delete rows in Sheet1 it will not delete the corresponding rows in Sheet2 (it only seems to be working with the first row?!).

Could you add something to the code to get these two details to work better? Thank you again for your effort!!!
 
Upvote 0
Hello Rick!
Thanks again for your kindness taking time to help me with this vba-issue. Now the macro works quite fine! But after testing it I found two things that isn´t really working as I thought it would.

First, if I don´t write anything in column D it will not copy column B to Sheet2. There may be rows were column D will have a blank value in Sheet1 and then I still want column B to be copied from Sheet1 to Sheet2.

Second, if I delete rows in Sheet1 it will not delete the corresponding rows in Sheet2 (it only seems to be working with the first row?!).

Could you add something to the code to get these two details to work better? Thank you again for your effort!!!
See if this modified code works the way you want...
Code:
Sub ExtractAllCaps()
  Dim R As Long, X As Long, Data As Variant, Result As Variant
  Data = Sheets("Sheet1").Range("B1", Sheets("Sheet1").Cells(Rows.Count, "B").End(xlUp).Offset(, 2))
  ReDim Result(1 To UBound(Data), 1 To 2)
  For R = 1 To UBound(Data)
    If Not Data(R, 1) Like "*[!A-Z0-9]*" Then
      X = X + 1
      Result(X, 1) = Data(R, 1)
      Result(X, 2) = Data(R, 3)
    End If
  Next
  Sheets("Sheet2").UsedRange.Clear
  Sheets("Sheet2").Range("A1").Resize(UBound(Result), 2) = Result
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,013
Messages
6,122,694
Members
449,092
Latest member
snoom82

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