Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-12-2012, 09:37 AM
wrighty50 wrighty50 is offline Excel 2007 - formula or macro/vba code required Windows Vista Excel 2007 - formula or macro/vba code required Office 2007
Novice
Excel 2007 - formula or macro/vba code required
 
Join Date: Mar 2012
Posts: 11
wrighty50 is on a distinguished road
Default Excel 2007 - formula or macro/vba code required

Hi all,


I run a report at work which I export into excel for further analysis. All of the data is presented fine in rows across. However one piece of data, i.e. the Account Number, which is a six digit number. This only appears once for each subset of data and I need to put this account number adjacent to each line item.

I realise this probably needs a macro but am not sure how to do this. I think I would need to add a loop, but I am a bit of a novice with vba and macros.

May be an offset forrmula could be written? Because the account number is consistently presented in the same location, however each set of company data varies in length.

I have attached an example (obviously the data is made up, but this is the exact way in which my report is presented). I have highlighted in yellow where each occurrence of the account number is and at the moment I have to manually copy that number to where I have highlighted in green. This is a shortened version of the data set and in reality there are several hundred Companys and thousands of line items

Any help would be greatly appreciated or even the code I could use

Thank you
Attached Files
File Type: xlsx example.....xlsx (12.4 KB, 49 views)
Reply With Quote
  #2  
Old 05-12-2012, 03:22 PM
macropod's Avatar
macropod macropod is offline Excel 2007 - formula or macro/vba code required Windows 7 64bit Excel 2007 - formula or macro/vba code required Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Wrighty,

Try:
Code:
Sub PropagateAcctIDs()
Application.ScreenUpdating = False
Dim LastRow As Long, i As Long, StrAcct As String
With ActiveSheet
  LastRow = .Cells.SpecialCells(xlCellTypeLastCell).Row
  For i = 1 To LastRow
    If Cells(i, 9).Value = "Account Number" Then
      StrAcct = Cells(i, 10).Value
    ElseIf IsDate(Cells(i, 8).Value) Then
      Cells(i, 13).Value = StrAcct
    ElseIf Cells(i, 1).Value = "Client Name" Then
      With Cells(i, 13)
        .Value = "ACCOUNT NUMBER"
        .Font.Bold = True
      End With
    End If
  Next
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 05-13-2012, 01:08 PM
wrighty50 wrighty50 is offline Excel 2007 - formula or macro/vba code required Windows Vista Excel 2007 - formula or macro/vba code required Office 2007
Novice
Excel 2007 - formula or macro/vba code required
 
Join Date: Mar 2012
Posts: 11
wrighty50 is on a distinguished road
Default

Hi Macropod,

thank you very much for your quick response. I give that code a try tomorrow and you know how it works.

Thanks again, much appreciated
Reply With Quote
  #4  
Old 05-13-2012, 02:24 PM
wrighty50 wrighty50 is offline Excel 2007 - formula or macro/vba code required Windows Vista Excel 2007 - formula or macro/vba code required Office 2007
Novice
Excel 2007 - formula or macro/vba code required
 
Join Date: Mar 2012
Posts: 11
wrighty50 is on a distinguished road
Default

Hi again Macropod,

Just tried your code and it works perfectly!

That's fantastic, thank you very much for your help, much appreciated

Wrighty50
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro or routine required evanhughes Outlook 0 11-18-2011 02:56 AM
Excel 2007 - formula or macro/vba code required VBA code from Excel 2007 in Excel 2010 csam63 Excel Programming 1 10-07-2011 10:46 AM
Excel 2007 - formula or macro/vba code required Formula to select description when code is entered Natasha Excel 1 09-25-2011 12:59 PM
Formula Help Required OTPM Excel 6 08-31-2011 02:58 AM
Excel 2007 - formula or macro/vba code required Need Macro or Formula Help mbocian Excel 2 04-28-2011 02:04 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:20 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft