Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4063756
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:46:02+00:00 2026-05-20T15:46:02+00:00

Following is my problem description A B C D 1 H1 H2 H3 H4

  • 0

Following is my problem description

      A    B    C    D     
   1  H1   H2   H3   H4   
   2  1    3    4    2      
   3  2    4    1    8     
   4  3    1    6    1       
   5  4    2    8    5           

First row has the headings. Column A has the serial number of the table. Columns B, C, and D are values coming out from some calculations. I want to write a VBA code such that the code finds the minimum value in the Column D, selects all the corresponding values of the row, copies and pastes just the values in a sheet named NewSheet.

For the given case above, the VBA code should identify that the Cell D4 has the minimum value, it should select the corresponding values in row 4 (from cells B4, C4 and D4), copy these selected values and paste the values in the cells P2,Q2 and R2 of ‘NewSheet’.

Since I am just a beginner, it will be highly appreciated if the responder can provide some comments that will help me to understand the code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T15:46:03+00:00Added an answer on May 20, 2026 at 3:46 pm

    This will do the trick.

    Option Explicit ' Forces you to declare variables. Helps prevent stupid mistakes.
    
    Sub Rabbit()
    
    ' Declare variables. Can also spread this throughout your code...
    Dim rngData As Range
    Dim rngTarget As Range
    Dim varData As Variant
    Dim iCounter As Long
    Dim iMinH4 As Long
    Dim dblMinH4 As Double
    Dim shtNew As Worksheet
    
    ' Where to get the data from (H1...H4 headers not included here)
    Set rngData = Worksheets("Sheet1").Range("A2").Resize(4, 4)
    
    ' Get all data from sheet at once. Faster than interrogating sheet multiple times.
    varData = rngData
    
    ' Get first entry. This is the minimum so far, by definition...
    iMinH4 = 1
    dblMinH4 = varData(1, 4)
    ' Go through all other entries to see which is minimum.
    For iCounter = LBound(varData, 1) +1 To UBound(varData, 1) ' +1 since first entry already checked
        If varData(iCounter, 4) < dblMinH4 Then
            ' This is the minimum so far.
            dblMinH4 = varData(iCounter, 4)
            iMinH4 = iCounter
        Else
            ' This is not the minimum.
            ' Do nothing.
        End If
    Next iCounter
    
    ' If creating new sheet is necessary, uncomment this:
    'Set shtNew = ActiveWorkbook.Worksheets.Add
    'shtNew.Name = "NewSheet"
    
    ' Where should the values go?
    Set shtNew = ActiveWorkbook.Worksheets("NewSheet")
    Set rngTarget = shtNew.Range("P2:R2")
    
    ' Copy the values over to NewSheet.
    rngData.Cells(iMinH4, 1).Resize(1, 3).Copy rngTarget
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following is the problem description: let c[n] be the catalan number for n
Given the following xml fragment: <Problems> <Problem> <File>file1</File> <Description>desc1</Description> </Problem> <Problem> <File>file1</File> <Description>desc2</Description> </Problem>
Edit 4: The main issue has been resolved - turned out the problem was
As requested, I'm giving a more detailed description of the problem... First off I
Following problem: I want to render a news stream of short messages based on
The following problem happens on both Safari and Chrome, so probably a WebKit issue.
I have the following problem: I have 2 Strings of DNA Sequences (consisting of
I have the following problem: I have overridden popViewControllerAnimated:(BOOL)animated of UINavigationController because I would
I have the following problem, I am implementing a queue abstraction with RavenDB in
I have the following problem: I have a generic EF repository using DbContext designed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.