Forum

Code to hide row no...
 
Notifications
Clear all

Code to hide row not working

9 Posts
4 Users
0 Reactions
225 Views
(@samir-sasasa)
Posts: 4
Active Member
Topic starter
 

Hi there,

I found somebody online writing the following code, but it doesn't work with me , could you help please: 

.Range(4&":"&89).EntireRow.Hidden = True

Thanks

 
Posted : 08/08/2023 12:08 pm
Philip Treacy
(@philipt)
Posts: 1632
Member Admin
 

Hi,

The syntax is not valid.  What are you trying to do with that code?

As an example, this line will hide Row 1

Range("A1").EntireRow.Hidden = False

regards

Phil

 
Posted : 08/08/2023 8:36 pm
(@samir-sasasa)
Posts: 4
Active Member
Topic starter
 

Hi Philip

First Off All, thank you for your reply because I'm really surprised,

I wanted to hide the rows mentioned into the code.

I'm following Randy to make an App , he wrote this  code, please check the link below " current time on youtube where he just wrote the code without any problem"

 

This one : .Range(4&":"&89).EntireRow.Hidden = True

And sure it doesn't work,

As for me ChatGPT gave me this one:

.Range("4:" & "89").EntireRow.Hidden = True

Is ChatGPT replace exactly Randy's code ?

And why Randy's code works with him and not with me ?

Thank you Philp

 
Posted : 09/08/2023 3:15 am
Philip Treacy
(@philipt)
Posts: 1632
Member Admin
 

Hi,

He may have written the code in the editor but I didn't see him run it.  If he ran it, it would generate an error because it is incorrect.  I also noticed other lines with the same mistake.

The correct code is

.Range("4:" & "89").EntireRow.Hidden = True

regards

Phil

 
Posted : 09/08/2023 7:32 pm
(@keebellah)
Posts: 373
Reputable Member
 

This is a typical case of users seeing code they found and using it without understanding what they're doing.

The most important thing I always tell the persons using my code is that you also need to read it as you would a book, code is processed line by line like when reading a book.

If the syntax is respected then you might understand what it is doing and will pave the way for VBA coding.

The answer ginven by the OP proves again the danger lying in blindly trusting GPT

 
Posted : 10/08/2023 2:56 am
(@samir-sasasa)
Posts: 4
Active Member
Topic starter
 

Hi there, 

Sure I try my best not only to copy codes but to understand,

I have the same problem with the following codes ?

 

.Filters.Add "All Picture Files", "*.jpg,*.Png,*.Gif", 1

 

If .Show <> -1 Then GoTo NoSelection

Best regards,

Samir.

 
Posted : 11/08/2023 4:11 pm
Philip Treacy
(@philipt)
Posts: 1632
Member Admin
 

Hi Samir,

Hard to help with that since it's out of context.  Need all the other code around it to see why it isn't working.

Phil

 
Posted : 11/08/2023 7:33 pm
(@samir-sasasa)
Posts: 4
Active Member
Topic starter
 

Hello Philip,

The whole code is:

Sub Vehicle_Addpic()

Dim Getfile As FileDialog
SetGetfile = Application.FileDialog(msoFileDialogFilePicker)
With Getfile
Title = "Add Vehicle Picture"
.Filters.Add "All Picture Files", "*.jpg,*.Png,*.Gif", 1
If .Show <> -1 Then GoTo NoSelection
Sheet1.Range("J13").Value = .SelectedItems(1)
Vehicle_ShowPic
NoSelection:
End With
End Sub

Regards

Samir.

 
Posted : 12/08/2023 1:24 am
(@debaser)
Posts: 838
Member Moderator
 

FYI, the only thing wrong with your initial code (assuming it's inside a With block) was that you were missing some spaces:

.Range(4 & ":" & 89).EntireRow.Hidden = True

 

Your last code is also missing a space in this line:

SetGetfile = Application.FileDialog(msoFileDialogFilePicker)

which should read:

Set Getfile = Application.FileDialog(msoFileDialogFilePicker)

 
Posted : 15/08/2023 3:26 am
Share: