• 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
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Delete , Cut , Paste with criteria|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / Delete , Cut , Paste with criteria|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 & MacrosDelete , Cut , Paste with criteria
sp_PrintTopic sp_TopicIcon
Delete , Cut , Paste with criteria
Avatar
Tapan Vahbe

Active Member
Members
Level 0
Forum Posts: 4
Member Since:
December 20, 2019
sp_UserOfflineSmall Offline
1
December 20, 2019 - 7:56 pm
sp_Permalink sp_Print

Hello!

When I select any particular entire row and run vba then it should delete

data in that row from B,C,D,E then J,K and S,T,U,V only. This is for delete.

If entire row is not selected then vba first inform to select the row.

 

Same system for Cut and Paste

 

Tried to search a lot on the net but did not get any answer.

If anyone can help me

Thanks

sp_AnswersTopicSeeAnswer See Answer
Avatar
Purfleet
England
Member
Members


Trusted Members
Level 4
Forum Posts: 412
Member Since:
December 20, 2019
sp_UserOfflineSmall Offline
2
December 20, 2019 - 10:00 pm
sp_Permalink sp_Print

Assuming you want to just delete the contents of the cells?

Sub DeleteSelectedInRow()

Dim r As Long

Dim ColsCount As Long

ColsCount = Selection.Columns.Count

Debug.Print ColsCount

If ColsCount <> 16384 Then
MsgBox "Please select entire row before continuing", vbCritical
Exit Sub
Else
End If

r = ActiveCell.Row

Range("b" & r).ClearContents
Range("c" & r).ClearContents
Range("d" & r).ClearContents
Range("e" & r).ClearContents
Range("j" & r).ClearContents
Range("k" & r).ClearContents
Range("s" & r).ClearContents
Range("t" & r).ClearContents
Range("u" & r).ClearContents

End Sub

 

Not sure where you want to paste for the copy and paste one

Avatar
Tapan Vahbe

Active Member
Members
Level 0
Forum Posts: 4
Member Since:
December 20, 2019
sp_UserOfflineSmall Offline
3
December 23, 2019 - 2:12 pm
sp_Permalink sp_Print

Thanks Purfleet

 

Its working fine for Delete.

For Cut and Paste it is similar.

First select the entire row ( if not selected then message) and then Cut.

After that select the other row and paste special. The cells data will be the same as in Delete.

 

Thanks again

Avatar
Purfleet
England
Member
Members


Trusted Members
Level 4
Forum Posts: 412
Member Since:
December 20, 2019
sp_UserOfflineSmall Offline
4
December 23, 2019 - 5:27 pm
sp_Permalink sp_Print

Okay, so the below code will copy the cells from the selected row as ask you to type in a destination row number

Sub CutNPasteSelectedRow()

Dim cRow As Long

Dim ColsCount As Long

Dim pRow As Long

ColsCount = Selection.Columns.Count

If ColsCount <> 16384 Then
MsgBox "Please select entire row before continuing", vbCritical
Exit Sub
Else
End If

cRow = ActiveCell.Row

pRow = InputBox("Please select the row to paste the results", vbCritical)

Range("b" & cRow).Cut Range("b" & pRow)
Range("c" & cRow).Cut Range("c" & pRow)
Range("d" & cRow).Cut Range("d" & pRow)
Range("e" & cRow).Cut Range("e" & pRow)
Range("j" & cRow).Cut Range("j" & pRow)
Range("k" & cRow).Cut Range("k" & pRow)
Range("s" & cRow).Cut Range("s" & pRow)
Range("t" & cRow).Cut Range("t" & pRow)
Range("u" & cRow).Cut Range("u" & pRow)

End Sub

sp_AnswersTopicAnswer
Answers Post
Avatar
Tapan Vahbe

Active Member
Members
Level 0
Forum Posts: 4
Member Since:
December 20, 2019
sp_UserOfflineSmall Offline
5
December 24, 2019 - 3:42 pm
sp_Permalink sp_Print

Thanks a lot Purfleet. Saved a lot of time because of the code.

Only in case of Delete code can it be made for multiple selection. 

However even this is ok.

Since the querry is solved do i need to tick mark the Useful Answer.

 

Thanks Again and Merry Christmas to you and all the other members.

SmileSmileSmile

Avatar
Purfleet
England
Member
Members


Trusted Members
Level 4
Forum Posts: 412
Member Since:
December 20, 2019
sp_UserOfflineSmall Offline
6
December 26, 2019 - 12:18 am
sp_Permalink sp_Print

Glad it was okay, could be made more efficent but as long as it works okay it will give you a start.

What is the issue with the delete part you mention 'Only in case of Delete code can it be made for multiple selection.' ?

Avatar
Tapan Vahbe

Active Member
Members
Level 0
Forum Posts: 4
Member Since:
December 20, 2019
sp_UserOfflineSmall Offline
7
January 4, 2020 - 4:37 pm
sp_Permalink sp_Print

Hello and sorry for delay in reply. Was on leave.

Can this topic be slightly extended more to make the working code more flexible.

As I started working on the above code I came across these issues.

The Delete part where pressing ctrl key I select multiple rows in a sheet and run the code.

The Cut & Paste is working fine since it is required in the same sheet at present.

But if I want to cut from the existing sheet and paste in the row in another sheet named

GENERAL. A separate code if want paste in another sheet.

 

Thanks

Happy New Year.

Avatar
Dave Morrison
Member
Members
Level 0
Forum Posts: 6
Member Since:
December 21, 2018
sp_UserOfflineSmall Offline
8
January 4, 2020 - 11:18 pm
sp_Permalink sp_Print

Normally you would have the code search a range to find a criteria. If criteria is found, then do something.

 

Attach a sample workbook showing your layout and your desired results.

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Tristram Sexton, Ben Hughes
Guest(s) 9
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 870
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
A.Maurizio: 202
Jessica Stewart: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
yashal minahil
Oluwadamilola Ogun
Yannik H
dectator mang
Francis Drouillard
Orlando Inocente
Jovitha Clemence
Maloxat Axmatovna
Ricardo Freitas
Marko Meglic
Forum Stats:
Groups: 3
Forums: 24
Topics: 6200
Posts: 27182

 

Member Stats:
Guest Posters: 49
Members: 31861
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.