首页 \ 问答 \ VBA userform_Get从附加文本框到单元格的值(VBA userform_Get Value from additional textboxes to cells)

VBA userform_Get从附加文本框到单元格的值(VBA userform_Get Value from additional textboxes to cells)

我不知道如何在VBA Userform中采取行动。

我有一个用户表单,它允许用户添加更多的文本框并将值输入到文本框。 我想从每个附加文本框中复制这些值以分隔单元格。 这是我所做的,但没有工作。

标签“点击后添加文本框 - 这是一种工作方式”

Private Sub CommandButton2_Click()
  x = Me.Controls.count + 1
  Set xx = Controls.Add("Forms.TextBox.1", "CtrlName" & x)
  xx.Top = x * 20 - 108
  xx.Left = 396
  xx.Width = 288
End Sub

标签“从文本框获取值cell_THIS不工作”

Private Sub CommandButton1_Click()
  Dim count as Integer
  Dim i as Integer
  count = Me.Controls.count - 9 ("I have 9 other controls, so need to - 9 to count the number of textboxes")
  For i = 1 To count
    Cells(i, 1).Select
    ActiveCell.Value = Me.Controls("TextBox" & i).Value
  Next i
End Sub

问题是Me.Controls ("TextBox" & I).Value 。 我在这里尝试了不同的功能,但仍然无法解决这个问题。


I don't know how to take action with the VBA Userform here.

I have a userform which allows users add more textboxes and type the value to the textboxes. I want to copy those values from each additional textbox to separate cells. This is what I did, but not working.

Label "Add textbox after clicking_THIS ONE IS WORKING"

Private Sub CommandButton2_Click()
  x = Me.Controls.count + 1
  Set xx = Controls.Add("Forms.TextBox.1", "CtrlName" & x)
  xx.Top = x * 20 - 108
  xx.Left = 396
  xx.Width = 288
End Sub

Label "Get value from textboxes to cell_THIS IS NOT WORKING"

Private Sub CommandButton1_Click()
  Dim count as Integer
  Dim i as Integer
  count = Me.Controls.count - 9 ("I have 9 other controls, so need to - 9 to count the number of textboxes")
  For i = 1 To count
    Cells(i, 1).Select
    ActiveCell.Value = Me.Controls("TextBox" & i).Value
  Next i
End Sub

The problem is the Me.Controls ("TextBox" & I).Value. I tried different funtions here, but still couldn't solve that.


原文:https://stackoverflow.com/questions/41651599
更新时间:2022-07-28 16:07

最满意答案

那是因为你只在密钥代码上运行它...

把它放在一个像这样的功能....

    function getMiles(){
    var firstValue = parseFloat($('#first').val()); // get value of field
    var secondValue = parseFloat($('#second').val()); // convert it to a float
    var thirdValue = parseFloat($('#third').val());
    $('#added').html(firstValue * secondValue ); 

    }

然后你就可以在keyup上运行那些代码,只要它改变....并且只需要在任何其他时间运行它....就像页面加载时...

$('input').keyup(getMiles); //this will do as you had it before...


 getMiles();//this can be used at top of script, or in a callback, 
            //so that it updates on page load, or on the google map callback 

例如,我不知道你是如何从谷歌获取数据的,但是让我们假装它是一个Jquery Ajax调用....那么你只需要在成功函数中调用getMiles() ....就像这样.. 。

$.ajax({
   url: "googlemapexample.php",
   dataType: "json",
   success: getMiles
   });

或者在完成功能....所以你可以做scuccess上的其他东西....

    $.ajax({
   url: "googlemapexample.php",
   dataType: "json",
   success: function(data){
    ///do some stuff here with data
    } }).done(getMiles);

Thats because you only have it running on the keyup code...

put it in a function like so....

    function getMiles(){
    var firstValue = parseFloat($('#first').val()); // get value of field
    var secondValue = parseFloat($('#second').val()); // convert it to a float
    var thirdValue = parseFloat($('#third').val());
    $('#added').html(firstValue * secondValue ); 

    }

Then you can run that code, on keyup for anytime it changes....and just run it any other time you need to....like when page loads etc...

$('input').keyup(getMiles); //this will do as you had it before...


 getMiles();//this can be used at top of script, or in a callback, 
            //so that it updates on page load, or on the google map callback 

Like for example, I don't know how you are getting the data from google, but lets pretend its a Jquery Ajax call....then you would just call getMiles() in the success function....like this...

$.ajax({
   url: "googlemapexample.php",
   dataType: "json",
   success: getMiles
   });

Or in the done function....so you can do other stuff on scuccess....

    $.ajax({
   url: "googlemapexample.php",
   dataType: "json",
   success: function(data){
    ///do some stuff here with data
    } }).done(getMiles);

相关问答

更多
  • 问题是,该函数是在页面元素完全加载之前执行的。 你可以将函数放在$(function() { }); 例如 $(function() { // Planning Filter var planningFilter = function () { // NOTE: I have multiple types of basic filters. // eg: Planning, Approved, Completed $("#jobGrid").bootgrid ...
  • 我已经使用以下代码完成了...序列化工作对我来说主要的是标题提供信息headers : { 'Content-Type': 'application/x-www-form-urlencoded' } app.controller('myForm',function($http,$scope){ $scope.saveCashbook=function() { $http({ method: "POST", url: 'cashbook/sav ...
  • 根据jQuery 文档 ,API只接受元素节点(不是JavaScript / jQuery 对象或选择器 ) 检查DOM元素是否是另一个DOM元素的后代。 仅支持元素节点; 如果第二个参数是文本或注释节点,$ .contains()将返回false。 注意:第一个参数必须是DOM元素,而不是jQuery对象或普通的JavaScript对象。 你应该改变代码 $(function () { alert($.contains(document.body, $("p")[0])) //alerts true ...
  • 您还可以将语言名称存储在图像的替代文本中(因此符合ADA)。 然后,您可以为td元素使用类选择器,并将替换文本替换为图像。 这样做的好处仍然是对屏幕阅读器友好。 编辑因为你有鼠标移动速度的问题,我建议不要使用.fadeIn和.fadeOut看下面的替代javascript。 所以,类似于以下(和小提琴) : 使用Javascript / jQuery的 $(document).on('mouseenter', '.showlangs td', function(event){ var _img = ...
  • 您说特定按钮正在动态加载到DOM,因此在此上下文中,您必须使用event-delegation来使代码正常工作。 通常,您的代码将在加载DOM后立即为类.delete注册元素的事件。 实际上我们当时没有任何具有该身份的元素,因此这个上下文选择event-delegation 。 我实际上不知道你的确切dom结构,所以我已经使用document来委托click事件,但你应该更喜欢该元素的一些静态父实现它, 尝试, $(document).on("click",".delete", function (e){ ...
  • 那是因为你只在密钥代码上运行它... 把它放在一个像这样的功能.... function getMiles(){ var firstValue = parseFloat($('#first').val()); // get value of field var secondValue = parseFloat($('#second').val()); // convert it to a float var thirdValue = parseFloat($('#third' ...
  • 你在第一个strBuff.push调用结束时终止你的onclick属性,使用单引号括起属性值并在其内容中 - 你必须混合你的引号: var strBuff = []; strBuff.push("
  • 你不能以这种方式链接它,你必须在动画完成后删除类作为回调: function getRightCol(){ $('#right-col').slideDown(200, function () { $(this).removeClass('hidden'); }); }; You can't chain it that way, you have to remove the class as callback after the animation completes: fu ...
  • Waypont插件的灵活工作方式就是这样做 var waypoint = new Waypoint({ element: document.getElementById('waypoint'), handler: function(direction) { console.log('Scrolled to waypoint!') } }) 你也可以试试这个 $('.team-member').waypoint(function (){ var thisE = $(this)[0] ...
  • 你有几个问题。 您正在定义click事件内部的函数并直接调用它。 因此,您的this变量的范围不正确,无法满足您的需求。 这也意味着每次单击#toggle-nav ,都会创建,调用,然后销毁该函数。 如果您在click事件之外声明它,则只创建一次,而不是每次单击都会重复使用它。 您正在使用event.stopPropagation()而您使用的参数名称是e 。 最后,您不需要将匿名函数传递给.click函数。 您可以按名称传递命名函数,并直接调用它。 这是您的代码清理了一点,以解决这些问题。 jQuery( ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)