CodingExcel VBA Macro

 

Press Ctrl+Enter to quickly submit your post
Quick Reply  
 
 
  
 From:  Mod_Inside (MODINSIDE)  
 To:  ALL
37924.1 

Hi

 

We have a fixed import file we run through excel for invoicing. It always has exactly 85 rows.

 

Is there a check in someway I can write to the begining of the macro if it has more or less than 85 rows it stops by displaying an error message?

 

The sheet concerned is called Main

 

Thanks in advance

0/0
 Reply   Quote More 

 From:  Queeg 500 (JESUSONEEZ)  
 To:  Mod_Inside (MODINSIDE)     
37924.2 In reply to 37924.1 
First thought is that it can be imported into an empty worksheet, use a countif statement to count the rows, and if it's OK, copy it into the correct worksheet, else show an error (and delete the imported crap).

That's how I'd do it but then I'm crap at coding and I'm sure there's a more elgant way.

--
"BrrrrAP BrrrrrAP!" - Westwood, 2008
0/0
 Reply   Quote More 

 From:  af (CAER)  
 To:  Mod_Inside (MODINSIDE)     
37924.3 In reply to 37924.1 
This should get you the last row of the first column:
VBA code:
Dim LastRow As Integer
Set Lastow = Main.Range("A65536").End(xlUp).Row
0/0
 Reply   Quote More 

 From:  Mod_Inside (MODINSIDE)  
 To:  af (CAER)     
37924.4 In reply to 37924.3 

Thanks Caer

 

The problem is I dont know what to do with it once ive got it!

 

Any ideas would be really appreciated

0/0
 Reply   Quote More 

 From:  af (CAER)  
 To:  Mod_Inside (MODINSIDE)     
37924.5 In reply to 37924.4 
Do with what, the code or the value it results in?
0/0
 Reply   Quote More 

 From:  Mod_Inside (MODINSIDE)  
 To:  af (CAER)     
37924.6 In reply to 37924.5 
I don't know how to show an error if the row returned is less than 85 or greater 85 in the sheet Main
0/0
 Reply   Quote More 

 From:  af (CAER)  
 To:  Mod_Inside (MODINSIDE)     
37924.7 In reply to 37924.6 
Oh, something like this should do it:
code:
If LastRow <> 85 Then
    PointlessVariable = MsgBox("Number of rows is not 85.", vbOKOnly, "YOU FAIL!")
End If

You could make it a bit more helpful by showing a different message depending on whether the number of rows is less than 85, or more.

edit:
Just in case you didn't know, '<>' means 'not equal to'. Sensible languages use '!=' or '!=='.
0/0
 Reply   Quote More 

 From:  Queeg 500 (JESUSONEEZ)  
 To:  af (CAER)     
37924.8 In reply to 37924.3 
See, knew there was a better way.

:'D

--
"BrrrrAP BrrrrrAP!" - Westwood, 2008
0/0
 Reply   Quote More 

 From:  Mod_Inside (MODINSIDE)  
 To:  af (CAER)     
37924.9 In reply to 37924.7 

Thanks Caer

 

Once i knew how it was supposed to be and a little tweak here and there it works a treat.

 

If i add a line it fails and if i take one away it fails. Brilliant thanks a lot

0/0
 Reply   Quote More 

Reply to All    
 

1–9

Rate my interest:

Adjust text size : Smaller 10 Larger

Beehive Forum 1.5.2 |  FAQ |  Docs |  Support |  Donate! ©2002 - 2024 Project Beehive Forum

Forum Stats