Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Junior Member
 
Posts: 2
Default Add to existing macro

Hi all, Is it possible that someone could help me add to the macro shown below
Need to add "dp" as an extra choice to enter in col H sheet A, and have that shown as column E in sheet B
Much appreciated if anybody can help

Here is a pic of what I mean




Sub paid()
Sheets("Current").Select
Dim ShA As Worksheet
Dim ShB As Worksheet
Dim DestCell As Range
Dim TargetRng As Range

Application.ScreenUpdating = False
Set ShA = Worksheets("Current")
Set ShB = Worksheets("Paid")
'Set DestCell = ShB.Range("A2")
Set DestCell = ShB.Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
Set TargetRng = ShA.Range("F2", ShA.Range("F" & Rows.Count).End(xlUp))

For Each cell In TargetRng
If cell.Value = "p" Then
ShA.Range("A" & cell.Row).Resize(1, 2).Copy DestCell
If cell.Offset(0, 2) = "ch" Then
DestCell.Offset(0, 2) = cell.Offset(0, 1)
Else
DestCell.Offset(0, 3) = cell.Offset(0, 1)
End If
Set DestCell = DestCell.Offset(1, 0)
cell.Value = "c"
End If
Next
Application.ScreenUpdating = True
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default Add to existing macro

Hello,

I think that a Select Case will work better than the If Then statement here. It will also be easier to add new values as necessary. Here is a modified version of the For...Next portion of your code that worked for me:

For Each cell In TargetRng
If cell.Value = "p" Then
ShA.Range("A" & cell.Row).Resize(1, 2).Copy DestCell

Select Case cell.Offset(0, 2)
Case "ch"
DestCell.Offset(0, 2) = cell.Offset(0, 1)
Case "ca"
DestCell.Offset(0, 3) = cell.Offset(0, 1)
Case Else
DestCell.Offset(0, 4) = cell.Offset(0, 1)
End Select

Set DestCell = DestCell.Offset(1, 0)
cell.Value = "c"
End If
Next
  #3   Report Post  
Junior Member
 
Posts: 2
Thumbs up

Quote:
Originally Posted by Ben McClave View Post
Hello,

I think that a Select Case will work better than the If Then statement here. It will also be easier to add new values as necessary. Here is a modified version of the For...Next portion of your code that worked for me:
Hi Ben
that works perfectly, and as you say new values can be easily added
Thanks very much for your time and assistance
much appreciated
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default Add to existing macro

No problem, I'm glad to hear it works.
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
modify existing macro SteveDB1 Excel Programming 7 March 11th 09 06:55 PM
modify existing macro SteveDB1 Excel Programming 2 November 18th 08 12:16 AM
add vbyesno to existing macro SteveDB1 Excel Programming 6 September 8th 08 10:42 PM
Macro to run an Existing Microsoft Access Macro Paul Dennis Excel Programming 1 November 6th 07 02:48 PM
Change to existing macro Jerry[_14_] Excel Programming 5 November 4th 03 01:51 PM


All times are GMT +1. The time now is 04:21 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"