PDA

View Full Version : Question about clear, clear contents



austenr
02-11-2020, 08:14 AM
I’m using a macro to clear a range of cells If I use clear or clear contents my macro doesn’t work anymore. If I use the delete key on the keyboard and paste other values into those cells then the macro works. Can’t figure out why?

Jan Karel Pieterse
02-11-2020, 08:39 AM
Please show your macro and tell us on what line you get which error exactly.

austenr
02-11-2020, 09:07 AM
Please show your macro and tell us on what line you get which error exactly.

the macro runs fine. Here is what I’m doing.

I copy and paste from a csv workbook into a macro enabled workbook. In the code there is a line that changes the csv to double (CDbl). Like I said it works fine the first pass and also works if you use the delete key to delete the data and replace it with new csv data.

I created a macro that that clears the data from a actixeX button. This is where the problem comes in. If I use ClrarContents or Clear the paste the csv data and run the macro it does not find matches but it should.

So the question is why does the macro run correctly when you use the delete key to clear the contents but if you use the macro to clear contents the next time you paste the data and run the macro no matching data is found. To me delete key or clear or clear contents is the same. But obviously not.

Dave
02-11-2020, 11:15 AM
Hi austenr. I see the CDbl code revision worked. Maybe post your macro that you're using to clear/delete the data. Dave

austenr
02-11-2020, 02:50 PM
Hi austenr. I see the CDbl code revision worked. Maybe post your macro that you're using to clear/delete the data. Dave


Private Sub CommandButton1_Click()
Range("a2:a1000").ClearContents
End Sub

basically just that 1 line. Also tried clear contents.

I would also like a way to copy cells in column A that have an X in column B which indicates a match to E8 and all subsequent matches on down so the user doesnt have to scroll down all the way. I know there is an offset way of doing it but cant get it to work.

Dave
02-11-2020, 05:13 PM
Maybe just append some code to the previous code. Where do U want to list the matches? U need to qualify your clear...

Dim LastRow As Integer
'clear "A"
With Sheets("Sheet1")
LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
.Range("A" & "1:A" & LastRow).Clear
End With

Dave

snb
02-12-2020, 03:48 AM
You have so little knowledge of VBA that anything is possible in 'your' code.
My compliments for not uploading your workbook and preventing others to help you.

austenr
02-12-2020, 06:51 AM
hello dave the matches should start in E8. as for the response from snb sometimes its better to say nothing and move on to the next thread instead of trying to belittle someone.

Dave
02-12-2020, 06:05 PM
"You have so little knowledge of VBA that anything is possible in 'your' code." ????? snb seems like you were referring to me but I'm guessing U were just funning with austenr. I'll pm austenr with anything further. Dave

snb
02-13-2020, 02:05 AM
@Dave the you in the second line is the same you in the first one (i.e. not you)

austenr
02-13-2020, 05:59 AM
@Dave the you in the second line is the same you in the first one (i.e. not you)

Snb. So if it’s not Dave and your going after me
Then I give nary a F about you. It’s people like you that give places a bad name.

snb
02-13-2020, 06:03 AM
Also tried clear contents.

Brrrr. Too lazy to use F1.