• 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

Validate three conditions and insert row|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / Validate three conditions and insert row|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 & MacrosValidate three conditions and inser…
sp_PrintTopic sp_TopicIcon
Validate three conditions and insert row
Avatar
Adriano Almeida

Active Member
Members
Level 0
Forum Posts: 5
Member Since:
July 30, 2022
sp_UserOfflineSmall Offline
1
July 30, 2022 - 5:51 am
sp_Permalink sp_Print

I'm working with a macro (contributed by a colleague on the forum) that inserts a line below whenever the answer is PC or NC.

====

Private Sub Worksheet_Change(ByVal Target As Range)

On Error Resume Next

If Not Intersect(Target, Range("V:V")) Is Nothing Then

Application.EnableEvents = False

Target = UCase(Target)

Application.EnableEvents = True

End If

On Error GoTo 0

 

If Target.Column <> 22 Or Target.Text <> "NC" And Target.Text <> "PC" Then Exit Sub

Rows(Target.Row + 1).Insert

Cells(Target.Row + 1, 23).Resize(, 42).Merge

Cells(Target.Row + 1, 23).Select

Cells(Target.Row + 1, 22).ClearContents

End Sub

====

 

How should be

--------------------

Block 1

---------------------

Question 1 = C

Question 2 = NC (Since the answer was NC, insert a line below question 2)

Question 3 = C

Question 4 = C

Question 5 = PC (Since the answer was PC, insert a line below question 5)

(As PC or NC answers appeared in this block, insert one more line below question 5)

---------------------

Block 2

---------------------

Question 1 = C

Question 2 = C

Question 3 = NC (Since the answer was NC, insert a line below question 3)

(As PC or NC answers appeared in this block, insert one more line below question 3)

---------------------

Block 3

---------------------

Question 1 = C

Question 2 = PC (Since the answer was PC, insert a line below question 2)

Question 3 = C

Question 4 = C

(As PC or NC answers appeared in this block, insert a line below question 4)

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1807
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
2
July 30, 2022 - 5:02 pm
sp_Permalink sp_Print

Hi Adriano,
Can you please upload a sample file with a manual result showing how the blocks should look like based on the block description you provided?

It will help me understand the exact structure you described in your scenario.

Avatar
Adriano Almeida

Active Member
Members
Level 0
Forum Posts: 5
Member Since:
July 30, 2022
sp_UserOfflineSmall Offline
3
August 1, 2022 - 7:54 am
sp_Permalink sp_Print

Hi Catalin,

I uploaded a spreadsheet with more details about the spreadsheet. 
Thanks
Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1807
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
4
August 2, 2022 - 3:07 am
sp_Permalink sp_Print

Hi Adriano,

Let's look closer at block 1 and 2 in your example:

-in block 1 you have 1 NC, and the code is supposed to add 1 row below the NC, AND another row under block 1.

-in block 2, you have 1 PC and 2 NC, your example shows 1 row added under each of these 3 PC-NC, but no additional rows under block 2.

You have to make the rules more clear, the current description don't match the example. The description says that when a user types PC in block 2, the code should insert a row under the edited line, AND another row under the current block.

With these rules, if a user types 3 PC-NC in a block, the code will add 3 rows under the 3 added PC/NC's, and 3 rows under the block. In you example block 2, I see only the 3 added rows under each PC/NC, but nothing under the block.

More rules are needed, unfortunately.

Thank you

Avatar
Adriano Almeida

Active Member
Members
Level 0
Forum Posts: 5
Member Since:
July 30, 2022
sp_UserOfflineSmall Offline
5
August 2, 2022 - 10:06 pm
sp_Permalink sp_Print
Hi Catalin,

I'm starting to study VBA.
Can you help me create this code?

Thank you.
Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1807
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
6
August 3, 2022 - 2:53 am
sp_Permalink sp_Print

Yes, I can help you, but clarify first the issues described above.

Thank you

Avatar
Adriano Almeida

Active Member
Members
Level 0
Forum Posts: 5
Member Since:
July 30, 2022
sp_UserOfflineSmall Offline
7
August 4, 2022 - 8:59 am
sp_Permalink sp_Print
Hi Catalin

follow more
explanations about the spreadsheet.
It is a worksheet is made up of blocks of questions. For each question, answers must be given.
The answers can be: C (conform); PC (partially compliant) or NC (non-compliant).
If the answer to a question is PC or NC, a line must be inserted below the question for a comment to be entered.
If the answer to a question is C, it is not necessary to insert any lines below the question.
At the end of the block, check:
If there was any NC or PC response in the block, a line must be inserted at the end of the block.

Thanks
Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1807
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
8
August 5, 2022 - 12:21 am
sp_Permalink sp_Print

Hi Adriano,

In the block 2 you sent, I see a new row ONLY under those 3 PC/NC, but no rows under the block:

block-2.pngImage Enlarger

According to your description, if in that block there is a PC/NC, we  should insert 2 rows, one under the current row and one under the block. Block 2 has 3 PC/NC, but I see only 3 new rows, not 6 as you wanted. Based on your description, block 2 should look like this:

block-2-based-on-description.pngImage Enlarger

 

Why is that?

Avatar
Adriano Almeida

Active Member
Members
Level 0
Forum Posts: 5
Member Since:
July 30, 2022
sp_UserOfflineSmall Offline
9
August 5, 2022 - 5:30 am
sp_Permalink sp_Print

Hi Catalin,

I found it easier to resend the worksheet with the drawing with the explanation.

With the drawing (before and after) it will be easier to understand.

Thank you

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Philip Treacy, Carlos Ferreira, Chandler Davis, baber Tufail
Guest(s) 7
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:
drsven
Annie Witbrod
wahab tunde
Cong Le Duc
Faisal Bashir
Ivica Cvetkovski
Blaine Cox
Shankar Srinivasan
riyepa fdgf
Hannah Cave
Forum Stats:
Groups: 3
Forums: 24
Topics: 6205
Posts: 27211

 

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