No Spaces with VBA

Please post any questions regarding the program here.

Moderator: 2020vision

No Spaces with VBA

Postby excelhasey » Sat Nov 23, 2013 2:12 pm

Good afternoon all,

In an Excel sheet I have a tab LiveData (sheet8) and within this tab there is a column of information that is constantly updated but sometimes there might be no data to add to a cell so it will be blank i.e.a2=6, a3=8, a4=blank, a5=1.5, a6=blank, a7=3 etc now I want another column (say column D of this tab) to list all the data from column A but without the blanks, so i.e.d2=6, d3=8, d4=1.5, d5=3 etc hence all the blank cells have been removed

Each event with change the data in Column A and also it is not known which cells will contain data and which will be blank, so how do I do this ??

How would you write this in VBA so it cleared all previous data in column D on opening the spreadsheet and then set about copying my data without the blanks ??

Any ideas anyone ??
excelhasey
 
Posts: 196
Joined: Sat May 22, 2010 4:57 pm
Location: North West

Postby Captain Sensible » Sat Nov 23, 2013 3:50 pm

Why don't you copy it all and just use regex to remove the blanks before it's written back to whatever cell you want.
User avatar
Captain Sensible
 
Posts: 2923
Joined: Sat Nov 19, 2005 2:29 pm

Postby Captain Sensible » Sat Nov 23, 2013 4:02 pm

I suppose a lot depends on what vba code you already use in there for where it can be slotted in. You could just use a range="" to clear any previous data and if you've some loop already in there have it check the data, if not blank then use the End(xlUp).Offset(1, 0) code to stick it on the sheet at the next available cell
User avatar
Captain Sensible
 
Posts: 2923
Joined: Sat Nov 19, 2005 2:29 pm

Postby excelhasey » Sat Nov 23, 2013 5:15 pm

Sorry Captain no idea what regex is

There is also a bit of VBA already in there pulled from advise of different people so I wouldn't know how to add End(xlUp).Offset(1, 0) correctly sorry

Do I just write End(xlUp).Offset(1, 0) ?? - How does in know which range I want it to remove the blanks from

Any chance of just adding a load of numbers in an excel sheet column A with some blanks in there and then and getting it to do another column copying the previous data but with no blanks and PM me so I can see how you have done it ??

If so can you save it as an excel file compatable with 2007 ??
excelhasey
 
Posts: 196
Joined: Sat May 22, 2010 4:57 pm
Location: North West

Postby Captain Sensible » Sat Nov 23, 2013 5:45 pm

Try this subroutine in a sheet and see if it'll do for you.

It just copies the values from A1 to A50 into D1 to D50 then removes the blanks

Code: Select all
Sub DeleteEmptyCells()
Range("D1:D50").Value = Range("A1:A50").Value

Range("D1:D50").SpecialCells(xlCellTypeBlanks).Delete Shift:=xlUp

End Sub
User avatar
Captain Sensible
 
Posts: 2923
Joined: Sat Nov 19, 2005 2:29 pm

Postby excelhasey » Sat Nov 23, 2013 6:09 pm

Could be me but I put code in a brand new blank workbook and added random data and blanks in column A on sheet 1 then added your code but nothing appears in column D sorry
excelhasey
 
Posts: 196
Joined: Sat May 22, 2010 4:57 pm
Location: North West

Postby Captain Sensible » Sat Nov 23, 2013 6:15 pm

You'll need to run the macro for it to do anything
User avatar
Captain Sensible
 
Posts: 2923
Joined: Sat Nov 19, 2005 2:29 pm

Postby excelhasey » Sat Nov 23, 2013 6:23 pm

Ok sorry yes that works and does what it says on the tin nice one thanks but ............

How do I get the excel worksheet to run the macro for me everytime any cell is changed / updated etc ??
excelhasey
 
Posts: 196
Joined: Sat May 22, 2010 4:57 pm
Location: North West

Postby excelhasey » Sat Nov 23, 2013 6:49 pm

Thanks Captain your a star I think I have done it now by using

Application.EnableEvents statements

Cool I have actually sorted a VBA problem myself - I think ........

Thanks mate
excelhasey
 
Posts: 196
Joined: Sat May 22, 2010 4:57 pm
Location: North West

Postby Captain Sensible » Sat Nov 23, 2013 8:09 pm

Nice one, after a while it kind of all sinks into place, just have to pay attention to where you put snippets of code so things happen at the right time rather than after the event and avoid your code going into loops
User avatar
Captain Sensible
 
Posts: 2923
Joined: Sat Nov 19, 2005 2:29 pm


Return to Help

Who is online

Users browsing this forum: Google [Bot] and 77 guests

Sports betting software from Gruss Software


The strength of Gruss Software is that it’s been designed by one of you, a frustrated sports punter, and then developed by listening to dozens of like-minded enthusiasts.

Gruss is owned and run by brothers Gary and Mark Russell. Gary discovered Betfair in 2004 and soon realised that using bespoke software to place bets was much more efficient than merely placing them through the website.

Gary built his own software and then enhanced its features after trialling it through other Betfair users and reacting to their improvement ideas, something that still happens today.

He started making a small monthly charge so he could work on it full-time and then recruited Mark to help develop the products and Gruss Software was born.

We think it’s the best of its kind and so do a lot of our customers. But you can never stand still in this game and we’ll continue to improve the software if any more great ideas emerge.