Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all 49851 articles
Browse latest View live

Looking for a Solution to add rows in a diff. sheet and copy cell values

$
0
0
Hi Excel Experts,

I am absolutely new to macros/VBA and need your assistance. I am looking for a macro which allows them to do multiple things
The workbook consists of 4 spreadsheets: 1. Circuit Register, 2. Piping Register, 3. Features Register, 4. Thickness Monitoring

- The first sheet "Circuit Register" does not need any programming - all entries here are user-defined
- In the sheet "Piping Register", columns A,B and C need to be populated with the entries defined in sheet 1 - this could be dropdown and hence data validation could work. The rest of te columns (i.e., D to I) on the "Piping Register" are manually defined by the user - this is where things get interesting
- In the "features register", the Macro needs to add multiple rows for each item/row added in the "Piping Register". The number of rows to be added in the "features register" is defined column I of the "Piping Register". For example: on the "Piping Register", the item 12"-PL-001-A2CSN has 6 features thereby the sheet "Features" register has 6 rows for this item
- In addition to adding rows on the sheet, each row needs to replicate columns C and D from the "piping register" in columns A and B of the features register. This needs to be replicated on all the rows that have been added for an item
- Columns C to L on the "Features Register" are defined by the user
- On the thickness monitoring sheet, multiple cell values from the "Features Regsiter need to be replicated. This needs to be done as follows:
1. Column A on the "Thickness Monitoring Register" is populated by Column "B" on the "Piping Register" (Line Number)
2. Column B on the "Thickness Monitoring Register" is populated by Column "D" on the "Piping Register" (Feature Type)
3. Column C on the "Thickness Monitoring Register" is populated by Column "E" on the "Piping Register" (Feature ID)
4. Column D on the "Thickness Monitoring Register" is populated by Column "F" on the "Piping Register" (Feature Size)
5. Column E on the "Thickness Monitoring Register" is populated by Column "J" on the "Piping Register" (NWT)
6. Column F on the "Thickness Monitoring Register" is populated by Column "K" on the "Piping Register" (CONC)

TIA
Attached Files

Excel Not calculating issue on one workbook

$
0
0
I am having a strange problem that is occurring on an excel workbook that has quite a bit of VB code in it. The formulas will not calculate. If I go into options, then formulas, Automatic will be on manual. I then check automatic, go back and the formulas still do not update. IF I use the Ctrl, Alt, Shift and F9 keys it will update. Then I close and save the file, come back and the option/formula settings is back at manual again. Other workbooks that I have code in work fine.

Does anyone have any idea what might be going on?

[SOLVED] Clearing only specific text in range

$
0
0
Hey everyone,

I'm stumped. Have a worksheet and assigned a macro button that will clear contents of a specific range. The clear button works but I just want to clear the cells that contain W while leaving the cells that are marked X.

Thanks
Attached Files

How to run all equations at once.

$
0
0
I am trying to do few things here. I am trying to figure out how to get rid of the Temp Critical, Pressure Critical and acentric factor combo boxes and have these value within the coding rather than being displayed in the combo boxes. I am also trying to figure out how would I go the program to make all the equations run at once for either or numerical method and the answer within the excel sheet.
Attached Files

Return First Expense Code

$
0
0
I am a novice and working with a data output into excel that is very "dirty" and with lots of inconsistencies preventing easy re-formatting of the data.

In the attached workbook I have a column with House #s. I need to return the Charge (Column M) corresponding to the first occurrence of Expense Code Q associated with a particular House #. Difficulties I am encountering:

1. The House Column contains a mix of (1) numbers formatted as text, with irrelevant [text] interspersed throughout the House Column
2. Spacing between columns
3. Trickiest part of the Code will be writing something that extracts the Charge associated with the first occurrence of "Q" in between identifying House #


Thank in advance you so much for your help. This website has been enormously beneficial for me as I try to learn VBA.
Attached Files

[SOLVED] Macro to find value using offset and generate pop up message box

$
0
0
I have text Variance in Col A on Sheet "Sales1"

where the value in the same row in Col d <>0 , then I would like a message box to appear stating the value

I have shown some sample data so you can see what I am trying to achieve



Your assistance is much appreciated

Need to delete rows from supplier stock list to only show stock I sell

$
0
0
Please Help!! 🙏

Its been a while since i've worked with excel hence asking what is probably a simple question.

But I have a sheet containing around 70 stock order numbers (like part number) for the products I sell from a supplier. Each day, I receive a report (.csv) from my supplier that has ALL (around 2000) of their available stock details and changes.

As I am only needing to update details for the products I am selling, I need to either delete rows from my suppliers list that don't match my stock order numbers OR alternatively, export a new .csv file with updated details of my products only with details from suppliers report.

So in summary if my stock order number (on one sheet) matches my suppliers stock order number (on a different sheet), I need the all details (approx. 19 columns) from suppliers report and if it doesn't, I don't need to know about it. (delete from suppliers csv??)

Hoping to get a speedy resolve as this issue is vital to integrate a new function in my online business product feed.

Many thanks in advance🙏

Userform, transfer characters to cells by typing

$
0
0
The code below allows you to edit the contents of a cell by typing ... and preserves the fonts every time a character is typed.
This works as intended.

Because there is a relatively large amount of code processed, every time a key is pressed, if you press several keys in quick succession, it throws the fonts out.
Try pressing a single key and wait until pressing the next, this is fine. Try pressing two or more keys in less than a second, the fonts are lost.

Is there a way to optimise the code so the issue is reduced.


ClassTyping
Code:

Option Explicit

Private WithEvents TextBoxTyping As MSForms.TextBox

Public Property Set Control(TextBoxTypingArgument As MSForms.TextBox)
    Set TextBoxTyping = TextBoxTypingArgument
End Property

'Part 1 of 2
Private Sub TextBoxTyping_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    Call UserForm1.TransferAtKeyDown(TextBoxTyping.SelLength, KeyCode)
End Sub

'Part 2 of 2
Private Sub TextBoxTyping_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    Call UserForm1.TransferAtKeyUp(TextBoxTyping.SelLength, KeyCode)
End Sub



Userform code
Code:

Option Explicit

'General
Private WithEvents MyApplication As Excel.Application
Public WithEvents cDelegate As ClassDelegate
'Ranges
Dim Cell As Range
'Textboxes
Private TextBoxes As Collection
Private mActiveTextBox As MSForms.TextBox
Dim TextBox As MSForms.TextBox
'Form editing by Typing
Dim TextBoxCollection As Collection
Public CursorLocationStore As Long
Public SelectionCountStore As Long
Public FontArrayStore As Variant

'INITIALIZE
Private Sub UserForm_Initialize()
    Set cDelegate = New ClassDelegate
    Call FormCreation(True)
    Call TypingControls
End Sub

'CREATE FORM
Private Sub FormCreation(BuildButtons As Boolean)
    Dim cEvents As ClassBoxes
    Dim Box As MSForms.TextBox
    Dim BoxTop As Long, BoxHeight As Long, BoxLeft As Long, BoxWidth As Long, BoxGap As Long
    Dim BoxName As String
    Dim MyControl As MSForms.Control
    Dim Index As Long
    'Miscellaneous
    Set MyApplication = Application
    BoxHeight = 35: BoxTop = 0: BoxLeft = 0: BoxWidth = TextBoxFrame.Width: BoxGap = 0
    Index = 1
    If TextBoxes Is Nothing Then
        Set TextBoxes = New Collection
    End If
    'Create textboxes
    For Each Cell In Selection
        If Index > TextBoxes.Count Then
            Set cEvents = New ClassBoxes
            Set cEvents.cDelegate = cDelegate
            BoxName = "TextBox" & Index
            Set Box = Me.TextBoxFrame.Controls.Add("Forms.Textbox.1", BoxName, True)
            Set cEvents.TextBoxGo = Box
            TextBoxes.Add cEvents
        Else
            Set Box = TextBoxes(Index).TextBoxGo
        End If
        With Box
            .Height = BoxHeight: .Top = BoxTop: .Left = BoxLeft: .Width = BoxWidth
            .AutoWordSelect = False
            .Font = "Courier New"
            .Font.Size = 20
            .Text = Cell.Formula
        End With
        Index = Index + 1
        BoxTop = BoxTop + BoxHeight + BoxGap
    Next Cell
    'Remove extra textboxes
    Do While TextBoxes.Count > Index
        TextBoxes.Remove TextBoxes.Count
    Loop
End Sub

'TEXT BOX EVENT
Private Sub cDelegate_TextBoxGoChanged(TextBoxGo As MSForms.TextBox)
    Set mActiveTextBox = TextBoxGo
End Sub

'CONTROLS FOR TYPED CHARACTERS
Private Sub TypingControls()
    Dim ctrl As MSForms.Control
    Dim obj As ClassTyping
    Set TextBoxCollection = New Collection
        For Each ctrl In Me.Controls
            If TypeOf ctrl Is MSForms.TextBox Then
                Set obj = New ClassTyping
                Set obj.Control = ctrl
                TextBoxCollection.Add obj
            End If
        Next ctrl
    Set obj = Nothing
End Sub

'AT KEY DOWN
Sub TransferAtKeyDown(SelectionCount As Long, ByVal KeyCode As MSForms.ReturnInteger)
    Dim Index As Long
    Dim i As Long
    On Error Resume Next 'Important: Seems to grind through without giving errors
    Index = 1
    SelectionCountStore = SelectionCount 'Used in KeyUp
    For Each Cell In Selection
        If TextBoxes(Index).TextBoxGo.Name = mActiveTextBox.Name Then
            With mActiveTextBox
                CursorLocationStore = .SelStart 'Used in KeyUp
                ReDim FontArrayStore(Len(Cell) - 1)
                For i = 1 To Len(Cell)
                    FontArrayStore(i - 1) = Cell.Characters(i, 1).Font.Name 'Used in KeyUp
                Next
            End With
        End If
    Index = Index + 1
    Next Cell
End Sub

'AT KEY UP
Sub TransferAtKeyUp(SelectionCount As Long, ByVal KeyCode As MSForms.ReturnInteger)
    Dim Index As Long
    Dim i As Long
    On Error Resume Next 'Seems to grind through without giving errors
    Index = 1
    For Each Cell In Selection
        If TextBoxes(Index).TextBoxGo.Name = mActiveTextBox.Name Then
            With mActiveTextBox
                Cell.value = mActiveTextBox.value
                For i = 1 To CursorLocationStore - 0
                    Cell.Characters(i, 1).Font.Name = FontArrayStore(i - 1)
                Next
                For i = CursorLocationStore + 1 To Len(Cell)
                    Cell.Characters(i, 1).Font.Name = FontArrayStore(i - 2)
                Next
            End With
        End If
    Index = Index + 1
    Next Cell
End Sub

'EXIT
Private Sub ButtonExit_Click()
    Unload Me
End Sub

'TERMINATE
Private Sub UserForm_Terminate()
    Dim Index As Long
    For Index = TextBoxes.Count To 1 Step -1
        Me.TextBoxFrame.Controls.Remove TextBoxes(Index).TextBoxGo.Name
        TextBoxes.Remove Index
    Next
    Set TextBoxes = Nothing
    Set MyApplication = Nothing
End Sub

Attached Files

[SOLVED] Macro to Exit Sub if d21 and D41 are both zero

$
0
0
I have tried to write code that where both D21 and D41 are both zero then exit sub , otherwise continue with macro

However if either D21 or D41 or both or not zero, macro still exits

see snippet of my code below

Code:

Sub Email_Debtors()
With Sheets("Debtors")
If Range("D21").Value = 0 And Range("D41").Value = 0 Then
Exit Sub
End If
End With

…..


Kindly amend my code

slight issue adding PDF shape.Addoleobject

$
0
0
The compiler will still stop on this item, you can hit F5 and continue and will add the pdf as it should.

Code:

.Shapes.AddOLEObject Filename:=tpath, _
            Link:=False, DisplayAsIcon:=False





Code:

With ActiveSheet  'store pdf in cell
             
            .Range("A2:S18").Select
            .Shapes.AddOLEObject Filename:=tpath, _
            Link:=False, DisplayAsIcon:=False
         
            End With
           
            With ActiveSheet.Shapes(I) 'format the object
           
          If I = 1 Then
            .Select
            .LockAspectRatio = msoFalse
            .Height = Range("A2:S19").Height
            .Width = Range("A2:S19").Width * 0.5
            .Left = Range("A2:S19").Left + (Range("A2:S19").Width - Selection.Width) / 2
            .Top = Range("A2:S19").Top + (Range("A2:S19").Height - Selection.Height) / 2
           
            Else
            .Select
            .LockAspectRatio = msoFalse
            .Height = Range("A2:S19").Height * 0.95
            .Width = Range("A2:S19").Width * 0.65
            .Left = Range("A2:AB19").Left + (Range("A2:AB19").Width - Selection.Width) / 2
            .Top = Range("A2:AB19").Top + (Range("A2:AB19").Height - Selection.Height) / 2
           
            End If
           
            End With

Refreshing number in ActiveX Text Box

$
0
0
Being in isolation is bad enough, but in isolation with a reluctant code is really annoying!!

In the attached spreadsheet I have 6 Text Boxes each of which is linked to a cell; TB1 = BR6, TB2 = BS2, TB3 = BT3 etc.
As I want to show and hide the Text Boxes I've put each in it's own module; TB1 Module10, TB2 Module12, TB3 Module13 and so on down to Module16.

The Code for each generates a random number at cell which is pasted as a value in the various cells each TB is linked to. Module10 / TB1 random number from cell BF7 is pasted as a value into BR6; Modules 12 - 16 get their random number from cell BF1 which are pasted as values in their linked cells.

The issue I have is that the Text Boxes don't show the numbers in the cells they are linked to! If I clear the cells BR6 to BW6 the first time I run the codes in the modules the text boxes come up blank. If I run them again they come up with the numbers generated on the first attempt (Or what appears to be random in the case of TB1).

How can I get them to show the number generated by the code in the relevant Module prior to displaying the text box?

There is a bit more activity prior to the Modules being called starting with the Command button 1 ("Press Here to Start Race X"), through the "Lights" code in Module 17 then on to the "Timing" sub that calls the above Modules.

As an aside, I could also do with the Text Boxes only showing the number to three decimal places i.e. 00.000

Thanks to whoever is wonderful enough to make this work for me!!

Cheers

Frankie

PS - Don't forget to wash your hands!!
Attached Files

i want to set up application key for app.

$
0
0
Hi all,

ive been putting together an application that i want to not sell but to do as a monthly subscription, what id like to know is how can i set it up that the app knows if a payment has been made and continue activation. or if payment is not made that the application stops working.

ive seen somewhere many many many many moons ago where paypal could be included some how, i cant find it now.

im open to options if anyone has ideas

thanks in advance

[SOLVED] Extract specific group in regex pattern

$
0
0
Hello everyone

I am trying with specific regex pattern like that
Code:

\d{1,2}(\.\s.*\s)\d{4}\s\d{2}:\d{2}
I need two points: first how to extract only the group number 1 (which is surrounded by two brackets (....)
The second point : how to replace this group with specific string?

Example of string: 31. Jan. 2020 14:67

** Note: I know that I can use excel basics and functions of split and so on to do such task..
I just need replies which is related to regular expressions.

.SentOnBehalfOfName - Not Working

$
0
0
I'm hoping someone can shed light on an EAC setting, or something else i'm unfamiliar with...

I can’t get the .SentOnBehalfOfName property to work for a particular department.
The users CAN manually select their mailbox, but when my code does they end up with an ‘undeliverable’ message.

I am under the impression that if they can manually select their mailbox, then they have the appropriate permissions to SendAs… Anyone ever run into this mystery?
Again, key points:
(1) This code works for myself & other shared mailboxes...
(2) The problem users CAN manually select their shared mailbox from their dropdown (From:)

Code:

    Dim OutApp As Object
    Dim OutMail As Object

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

        With OutMail
            .To = “”
            .SentOnBehalfOfName = "theirsharedmailbox@here.com"
            .CC = ""
            .BCC = ""
            .Subject = “FINAL"
            .Body = "Attached are the…”
            .Attachments.Add (FilePath)
            .Display
        End With

dropdown.click() get called all the time when i change values

$
0
0
Hi, I'm fairly new to VBA on excel so forgive me if the question is really stupid.

In my code i have a drop down that refers to cells containing 10,11,12.

if i do something like this

dropdown.value = 12

somewhere else in the code , then the method called dropdown().click gets called ?, why?

how can i reset the value to 12 if its currently selected as 10 for instance? with any method being called?


think im getting methods click and change mixed up, and possibly text and value as well !

VBA: Total sum range

$
0
0
Hi,

have the code below can I change it to:

1. Add total of printed
2. to print only due dates (select due date range) instead


Code:

Sub PRINT_DUE()
Dim rngToPrint As Range



Const Title As String = "Select Print Area"
Const Message As String = "Please select a range"

On Error Resume Next
Set rngToPrint = Application.InputBox(Message, Title, , , , , , 8)
'the 8 is the type of input to expect, in this case a range
On Error GoTo 0
If rngToPrint Is Nothing Then
MsgBox "You cancelled!"
Exit Sub
End If

thanks.

[SOLVED] Not sure why this query does not work

$
0
0
Hi,

I'm trying to activate a CommandButton next to a field as late in the writing of the string as possible.
He is typing out his email address and for some reason this does not work:

If Len(TextBox8.Value) + Len(TextBox7.Value) + TextBox5.Value = TextBox4.Value Then
CommandButton2.Enabled = True
End If

TextBox8 is a string
TextBox7 is a string
TextBox5 is a number
TextBox4 is a number

TextBox8 is the string after the "at"
TextBox7 is the string before the "at"
TextBox5 is the count of "at" in the email as a number
TextBox4 is the numeric length of the whole (incl. the "at" symbol) email.

Copy Paste All Except Comments Issue

$
0
0
I have a template file where I have had to add a number of images as tick marks. These images / tick marks are all over the worksheet in different locations.

After this template pulls data from our accounting system, I need to then copy/paste these values and tick marks into another identical workbook that does not have those images, but does have cell comments and notes that I need to keep.

So I'm looking for a way to possibly copy everything (selected cells) from the template file except the comments.

Is that a simple thing to do?

Thanks,
PT

VBA, Multiple SMS message, Getting the code to send only the lines with text and stop

$
0
0
Evening all, trying to finish off some code for automated sms.
It all works however it will send sms/emails for every cell from 8-55 including the blanks. Looking for a way I can send only the cells with values in.
The line of code I am working on is below and attached is the spreadsheet I am using.

For i = 8 to 55

Filtering unhidden columns

$
0
0
I have a project I am working on that hides 2 of 41 different columns. The 2 that are shown are dependent on a specific cell value. I have a code that will hide or unhide columns based on that cell value.
What I want to do after I have the correct columns is apply a filter to each automatically. The first column will be filtered by specific text, the 2nd will be filter by number greater than 0, or vice/versa.
Since there are 41 different combinations (the first column is always the same) I am having a hard time figuring out to filter just the unhidden columns.

After this filtering, plan on selecting the available data that is not hidden and copy/paste values onto another sheet.

I am not stuck to the above process, if someone has a better idea, but I am stuck with the 41 columns.
Viewing all 49851 articles
Browse latest View live