UserForm VBA: Find & Delete Range

Big Lar

Well-known Member
Joined
May 19, 2002
Messages
554
This loads the data onto Sheets("GROSS")

Code:
[FONT=Arial][FONT=Verdana]Private Sub CommandButton1_Click()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>[/FONT][/FONT]
[FONT=Arial][FONT=Verdana]Sheets("GROSS").Unprotect<o:p></o:p>[/FONT][/FONT]
[FONT=Arial][FONT=Verdana]Sheets("NET").Unprotect<o:p></o:p>[/FONT][/FONT]
[FONT=Arial][FONT=Verdana]Sheets("<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /><st1:place w:st="on">PO</st1:place>").Unprotect<o:p></o:p>[/FONT][/FONT]
[FONT=Arial]<o:p></o:p>[/FONT]
[FONT=Arial][FONT=Verdana]Application.ScreenUpdating = True<o:p></o:p>[/FONT][/FONT]
[FONT=Arial]<o:p></o:p>[/FONT]
[FONT=Arial][FONT=Verdana]Dim iRow As Long<o:p></o:p>[/FONT][/FONT]
[FONT=Arial][FONT=Verdana]Dim ws As Worksheet<o:p></o:p>[/FONT][/FONT]
[FONT=Arial][FONT=Verdana]Dim FullName As String<o:p></o:p>[/FONT][/FONT]
[FONT=Arial][FONT=Verdana]Dim CLoc As Range<o:p></o:p>[/FONT][/FONT]
[FONT=Arial][FONT=Verdana]Set ws = Worksheets("GROSS")<o:p></o:p>[/FONT][/FONT]
[FONT=Arial]<o:p></o:p>[/FONT]
[FONT=Arial][FONT=Verdana]   FullName = Me.ComboBox1.Value<o:p></o:p>[/FONT][/FONT]
[FONT=Arial][FONT=Verdana]   Set CLoc = ws.Columns("A:A").Find(What:=FullName, After:=ws.Cells(10, 1), LookIn:= _<o:p></o:p>[/FONT][/FONT]
[FONT=Arial][FONT=Verdana]                           xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:= _<o:p></o:p>[/FONT][/FONT]
[FONT=Arial][FONT=Verdana]                           xlNext, MatchCase:=False, SearchFormat:=False)<o:p></o:p>[/FONT][/FONT]
[FONT=Arial][FONT=Verdana]   If CLoc Is Nothing Then<o:p></o:p>[/FONT][/FONT]
[FONT=Arial][FONT=Verdana]       iRow = ws.Cells(Rows.Count, 1) _<o:p></o:p>[/FONT][/FONT]
[FONT=Arial][FONT=Verdana]              .End(xlUp).Offset(1, 0).Row<o:p></o:p>[/FONT][/FONT]
[FONT=Arial][FONT=Verdana]   Else<o:p></o:p>[/FONT][/FONT]
[FONT=Arial][FONT=Verdana]       iRow = CLoc.Row<o:p></o:p>[/FONT][/FONT]
[FONT=Arial][FONT=Verdana]   End If<o:p></o:p>[/FONT][/FONT]
[FONT=Arial]<o:p></o:p>[/FONT]
[FONT=Arial][FONT=Verdana]'copy the data to the GROSS Sheet<o:p></o:p>[/FONT][/FONT]
[FONT=Arial][FONT=Verdana]ws.Cells(iRow, 1).Value = Me.ComboBox1.Value<o:p></o:p>[/FONT][/FONT]
[FONT=Arial][FONT=Verdana]ws.Cells(iRow, 2).Value = Me.TextBox4.Value<o:p></o:p>[/FONT][/FONT]
[FONT=Arial][FONT=Verdana]ws.Cells(iRow, 3).Value = Me.TextBox5.Value<o:p></o:p>[/FONT][/FONT]
[FONT=Arial][FONT=Verdana]ws.Cells(iRow, 4).Value = Me.TextBox6.Value<o:p></o:p>[/FONT][/FONT]
[FONT=Arial][FONT=Verdana]etc…etc[/FONT][/FONT]
<o:p></o:p>
<o:p></o:p>
<o:p></o:p>
Occasionally, I have to delete a range “A:Y”<o:p></o:p>
Help me find FullName on Sheet(“GROSS”) and delete that range. I can’t delete the entire row due to labels and formulae in Columns AA:AG<o:p></o:p>
<o:p></o:p>
I’m thinking another CommandButton and UserForm TextBox??? That I can handle. It’s the Find and delete code that’s got my wheels spinning.

Thanks for your consideration.<o:p></o:p>
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
This is what I've got working...so far:

Code:
[FONT=Verdana]Private Sub UserForm_Initialize()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>[/FONT]
[FONT=Verdana]Dim x&<o:p></o:p>[/FONT]
[FONT=Verdana]With Sheets("GROSS")<o:p></o:p>[/FONT]
[FONT=Verdana]For x = 10 To .Cells(Rows.Count, "A").End(xlUp).Row<o:p></o:p>[/FONT]
[FONT=Verdana]ComboBox1.AddItem (.Range("A" & x).Value)<o:p></o:p>[/FONT]
[FONT=Verdana]Next x<o:p></o:p>[/FONT]
[FONT=Verdana]End With<o:p></o:p>[/FONT]
[FONT=Verdana]End Sub[/FONT]
 
[FONT=Verdana]Private Sub CommandButton1_Click()[/FONT]
[FONT=Verdana]Dim iRow                        As Long<o:p></o:p>[/FONT]
[FONT=Verdana]Dim ws                          As Worksheet<o:p></o:p>[/FONT]
[FONT=Verdana]Dim FullName              As String<o:p></o:p>[/FONT]
[FONT=Verdana]Dim CLoc                        As Range<o:p></o:p>[/FONT]
[FONT=Verdana]Set ws = Worksheets("GROSS")<o:p></o:p>[/FONT]
[FONT=Verdana]FullName = Me.ComboBox1.Value<o:p></o:p>[/FONT]
[FONT=Verdana]Set CLoc = ws.Columns("A:A").Find(What:=FullName, After:=ws.Cells(1, 1), LookIn:= _<o:p></o:p>[/FONT]
[FONT=Verdana]                   xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:= _<o:p></o:p>[/FONT]
[FONT=Verdana]                   xlNext, MatchCase:=False, SearchFormat:=False)<o:p></o:p>[/FONT]
[FONT=Verdana]If CLoc Is Nothing Then<o:p></o:p>[/FONT]
[FONT=Verdana]iRow = ws.Cells(Rows.Count, 1) _<o:p></o:p>[/FONT]
[FONT=Verdana]      .End(xlUp).Offset(1, 0).Row<o:p></o:p>[/FONT]
[FONT=Verdana]Else<o:p></o:p>[/FONT]
[FONT=Verdana]iRow = CLoc.Row<o:p></o:p>[/FONT]
[FONT=Verdana]End If<o:p></o:p>[/FONT]
[FONT=Verdana]<o:p></o:p><o:p></o:p>[/FONT]
[FONT=Verdana]End Sub[/FONT]
<o:p></o:p>

So what do I do next?:confused:
 
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,530
Members
448,969
Latest member
mirek8991

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