• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

COPY AND PASTE CONDITIONALLY|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / COPY AND PASTE CONDITIONALLY|VBA & Macros|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumVBA & MacrosCOPY AND PASTE CONDITIONALLY
sp_PrintTopic sp_TopicIcon
COPY AND PASTE CONDITIONALLY
Avatar
Sholtan Singh
Member
Members
Level 0
Forum Posts: 28
Member Since:
July 29, 2018
sp_UserOfflineSmall Offline
1
April 18, 2020 - 7:47 pm
sp_Permalink sp_Print

All files are located in a different path
vba code will be placed in a macro.xlsm
i have two files 1.xls & 2.csv
check wheather column H of 1.xls is greater or lower than column D of 1.xls
if column H of 1.xls is greater than column D of 1.xls then match column I of 1.xls with column B of 2.csv & if it matches then put this symbol "<" in column D of 2.csv & copy paste the data of column K of 1.xls in column E of 2.csv
or
if column H of 1.xls is lower than column D of 1.xls then match column I of 1.xls with column B of 2.csv & if it matches then put this symbol ">" in column D of 2.csv & copy paste the data of column K of 1.xls in column E of 2.csv

save and close both the file
plz help me in solving this problem by vba1.PNGImage Enlarger

result.PNGImage Enlarger

sp_PlupAttachments Attachments
  • sp_PlupImage 1.PNG (17 KB)
  • sp_PlupImage result.PNG (9 KB)
Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1529
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
2
April 18, 2020 - 11:09 pm
sp_Permalink sp_Print

Hi Sholtan,

This sounds like homework.  Have you tried to solve it yourself?  Please attach your attempt and I'll be happy to guide you.

Regards

Phil

Avatar
Sholtan Singh
Member
Members
Level 0
Forum Posts: 28
Member Since:
July 29, 2018
sp_UserOfflineSmall Offline
3
April 19, 2020 - 4:04 am
sp_Permalink sp_Print

Philip Sir i dont know much about vba 

but i know how to open the file by vba  actually i am unable to write the condition in vba language so can u plz help me out here this was very tricky for me so i directly asked for help 

Avatar
Sholtan Singh
Member
Members
Level 0
Forum Posts: 28
Member Since:
July 29, 2018
sp_UserOfflineSmall Offline
4
April 22, 2020 - 2:41 pm
sp_Permalink sp_Print

Sub test() Dim wb1 As Workbook, wb2 As Workbook Dim ws1 As Worksheet, ws2 As Worksheet Dim rg1 As Range, i As Long, c As Range Set wb1 = Workbooks.Open("C:\Users\WolfieeeStyle\Desktop\1.xls") Set wb2 = Workbooks.Open("C:\Users\WolfieeeStyle\Desktop\Alert..csv") Set ws1 = wb1.Worksheets.Item(1) Set ws2 = wb1.Worksheets.Item(1) Set rg1 = ws1.Cells(1, 1).CurrentRegion With rg1 For i = 2 To rg1.Rows.Count If .Cells(i, 8) > .Cells(i, 4) Then c = ws2.Columns(2).Find(.Cells(i, 9)) If Not c Is Nothing Then c.Offset(, 2).Value = "<" c.Offset(, 3).Value = .Cells(i, 11) End If Else c = ws2.Columns(2).Find(.Cells(i, 9)) If Not c Is Nothing Then c.Offset(, 2).Value = ">" c.Offset(, 3).Value = .Cells(i, 11) End If End If Next i End With wkb1.Close SaveChanges:=True wkb2.Close SaveChanges:=True End Sub

Avatar
Sholtan Singh
Member
Members
Level 0
Forum Posts: 28
Member Since:
July 29, 2018
sp_UserOfflineSmall Offline
5
April 22, 2020 - 2:42 pm
sp_Permalink sp_Print sp_EditHistory

i tried the code but i met with the error with this line c = ws2.Columns(2).Find(.Cells(i, 9))

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1529
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
6
April 23, 2020 - 9:53 pm
sp_Permalink sp_Print

Hi,

Please attach all the files you are working with so I don't have to recreate them.

Thanks

Phil

Avatar
Sholtan Singh
Member
Members
Level 0
Forum Posts: 28
Member Since:
July 29, 2018
sp_UserOfflineSmall Offline
7
April 24, 2020 - 4:11 am
sp_Permalink sp_Print

plz see the below attachment

Avatar
Sholtan Singh
Member
Members
Level 0
Forum Posts: 28
Member Since:
July 29, 2018
sp_UserOfflineSmall Offline
8
April 24, 2020 - 9:11 pm
sp_Permalink sp_Print
  1. Sub Not_tested()
  2. Dim wkb1 As Workbook, wkb2 As Workbook
  3. Dim sBk1 As String, sBk2 As String
  4. Dim ws1 As Worksheet, ws2 As Worksheet
  5. Dim rg1 As Range, i As Long, c As Range
  6.  
  7.  
  8.  
  9. sBk1 = Application.GetOpenFilename("Excel Files (*.xls*), *.xls*")
  10. sBk2 = Application.GetOpenFilename("CSV Files (*.csv), *.csv")
  11. Set wkb1 = Workbooks.Open(sBk1)
  12. Set wkb2 = Workbooks.Open(sBk2)
  13. Set ws1 = wkb1.Worksheets("1-Sheet1")
  14. Set ws2 = wkb2.Worksheets("Alert")
  15. Set rg1 = ws1.Cells(1, 1).CurrentRegion
  16. With rg1
  17. For i = 2 To rg1.Rows.Count
  18. If .Cells(i, 8) > .Cells(i, 4) Then
  19. Set c = ws2.Columns(2).Find(.Cells(i, 9))
  20. If Not c Is Nothing Then 'if match found
  21. c.Offset(, 2).Value = "<"
  22. c.Offset(, 3).Value = .Cells(i, 11)
  23. End If
  24. Else
  25. Set c = ws2.Columns(2).Find(.Cells(i, 9))
  26. If Not c Is Nothing Then 'if match found
  27. c.Offset(, 2).Value = ">"
  28. c.Offset(, 3).Value = .Cells(i, 11)
  29. End If
  30. End If
  31. Next i
  32. End With
  33. End Sub
Avatar
Sholtan Singh
Member
Members
Level 0
Forum Posts: 28
Member Since:
July 29, 2018
sp_UserOfflineSmall Offline
9
April 24, 2020 - 9:12 pm
sp_Permalink sp_Print

Problem Solved 

Thnx Alot Sir for ur great help

Avatar
Jim Leo
Guest
Guests
10
April 25, 2020 - 6:45 pm
sp_Permalink sp_Print sp_EditHistory

Thank you for sharing

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Sherry Fox, Cassie Bernier
Guest(s) 10
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 873
Purfleet: 414
Frans Visser: 346
David_Ng: 306
lea cohen: 222
Jessica Stewart: 215
A.Maurizio: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
Abisola Ogundele
MARTYN STERRY
Rahim Lakhani
Ngoc Qui Nguyen
Clement Mansfield
Rose .
Bindu Menon
Baruch Zemer
Purple RainbowBenefactor
MOTH Junkie
Forum Stats:
Groups: 3
Forums: 24
Topics: 6350
Posts: 27773

 

Member Stats:
Guest Posters: 49
Members: 32317
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.